Jump to content


MySQL Selection and editting


2 replies to this topic

#1 Forgotten

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 06 November 2005 - 07:39 PM

This is the problem

<?php

mysql_connect('localhost','fake','fake') or die(mysql_error());

mysql_select_db('djill_main') or die(mysql_error());

$mysqlnum = mysql_query("SELECT `id` FROM `affiliates` ORDER BY `id` DESC LIMIT 0,1");

echo $mysqlnum;

// if mysqlnum = 5 then why echoing $mysqlnum shows "Resource id #3"??

?>

That code is here: http://djillusion.ze...m/v2/intest.php

[EDIT] I realised that my script inserts the id before the echoing so I dont need to increase it, but even when echoing the unmodified variable, it still shows Resource id #3

Edited by Forgotten, 06 November 2005 - 08:08 PM.


#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 06 November 2005 - 08:41 PM

Quick simple explaination... mysql_query() returns a resource id. Use the following links for more info.
http://php.net/manua...mysql-query.php
http://php.net/manua...fetch-array.php

Word of advice, bookmark php.net, it'll answer more questions then you can think to ask :yoda:

#3 Forgotten

    Young Padawan

  • Members
  • Pip
  • 63 posts

Posted 06 November 2005 - 09:42 PM

but what Im trying to do is retrieve info from a table, one of the coloumns are entitled "id". In phpMyAdmin it tested my syntax and it displayed exactly what I wanted it to be. Why is it being so difficult? and I to use the fetch array instead of the mysql query? and if so, what would be proper syntax?

Thanks again.

[EDIT] Would this be proper?
<?php

mysql_connect('localhost','****','******') or die(mysql_error());

mysql_select_db('djill_main') or die(mysql_error());

$mysqlnum = mysql_query("SELECT `id` FROM `affiliates` ORDER BY `id` DESC LIMIT 0,1");

$mysqlurl = mysql_fetch_row($mysqlnum);

echo $mysqlurl[0];

?>

[EDIT #2] Alright! it works! You, sir, are an amazing man! Thanks for all of your help with my troublesome questions.

Edited by Forgotten, 06 November 2005 - 09:49 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users