dominod Posted July 15, 2010 Share Posted July 15, 2010 Hi I am having troubles extracting data from my MySQL database.. The strange thing is that this code has worked before.. I just copied and pasted (changing the nessessary names of cource). <?php ini_set("display_errors", true); error_reporting(-1); include("connect.php"); $extract = mysql_query("SELECT * FROM suggest"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_array($extract)) { $url[$i]=$row['url']; $i++; } $id=1; while($id < count($name)) { echo "The URL is " . $url[$id] . "<br />"; $id++; } ?> And the error msg I get is: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/haukaas/public_html/new/suggest-search-engine/admin/index.php on line 8 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/haukaas/public_html/new/suggest-search-engine/admin/index.php on line 10 Notice: Undefined variable: name in /home/haukaas/public_html/new/suggest-search-engine/admin/index.php on line 17 Can anyone help me? Link to comment https://forums.phpfreaks.com/topic/207838-error-when-extracting-data-from-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted July 15, 2010 Share Posted July 15, 2010 Make the query execution like this. (When done, remove the or die() before using on a live site.) $extract = mysql_query("SELECT * FROM suggest") or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/207838-error-when-extracting-data-from-mysql/#findComment-1086515 Share on other sites More sharing options...
dominod Posted July 15, 2010 Author Share Posted July 15, 2010 Ok now it works ... I was trying to connect to the wrong database (Stupid me! Yes I know!) I also made some changes to the code and now all the error msg is gone and it is diplaying the last entry in the mysql db. How can I make it display all entries? Here is the code: <?php ini_set("display_errors", true); error_reporting(-1); include("connect.php"); $extract = mysql_query("SELECT * FROM suggest"); $numrows = mysql_num_rows($extract); while ($row = mysql_fetch_array($extract)) { $url=$row['url']; } echo "The URL is " . $url . "<br />"; ?> Link to comment https://forums.phpfreaks.com/topic/207838-error-when-extracting-data-from-mysql/#findComment-1086539 Share on other sites More sharing options...
dominod Posted July 15, 2010 Author Share Posted July 15, 2010 Nevermind, DigitalPoint helped me out Link to comment https://forums.phpfreaks.com/topic/207838-error-when-extracting-data-from-mysql/#findComment-1086562 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.