cs1h Posted April 18, 2008 Share Posted April 18, 2008 Hi, I have a script which is designed to retrieve one set of data from one database and then use part of the information to get more data from another database. It is then meant to display the data in the table below. The code is <?php mysql_connect("localhost","fff","fff"); mysql_select_db("fff") or die("Unable to select database"); $art = $_GET['id']; $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "No results please try a different <a href=reports.php>search</a>."; } else { while($row = mysql_fetch_array($result)) { $Country = $row['country']; $Type = $row['type']; $Title = $row['Title']; $Abs = $row['Abstract']; $Auth = $row['name']; $Art = $row['Article']; $Photo = $row['photo']; $code1 = $row['code1']; $email = $row['Email']; } } ?> <?php mysql_connect("localhost","fff","fff"); mysql_select_db("fff") or die("Unable to select database"); $sql2 = "SELECT * FROM ac_users WHERE username=$email"; $result2 = mysql_query($sql2); $num_rows2 = mysql_num_rows($result2); if($num_rows2 == 0) { echo "No results please try a different <a href=reports.php>search</a>."; } else { while($row2 = mysql_fetch_array($result2)) { $avatar = $row2['avatar']; } } ?> <?php echo "<div id=\"more_container\"><img src=\"/avatar/$avatar\" width=\"56\" height=\"56\" class=\"more_author_photo\" /> <div id=\"more_title\"><span class=\"more_author\">Volunteer Overseas, $Country</span><span class=\"comment_stars\"><img src=\"stars_5.png\"/></span></div> <div id=\"more_author\"><span class=\"more_wrote\">posted by</span><span class=\"more_author\"> $Auth </span><span class=\"more_review_count\">3 Reviews</span></div> <div class=\"more_abstract\">$Abs</div> <img src=\"$Photo\" class=\"more_author_photo\" /> <div class=\"more_abstract\">$Art</div> <div class=\"more_footer\"> <div id=\"more_copyright\">Copyright © $Auth</div> <div id=\"more_reference\">Reference Id: $code1</div> </div> </div>"; ?> It gathers all the data from the first databse and displays it in the table but the second database comes up with this error. Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\Inetpub\vhosts\myroho.com\httpdocs\ssi_more.php on line 36 Can anyone help? Thanks, Colin Quote Link to comment https://forums.phpfreaks.com/topic/101720-solved-help-retrieving-data/ Share on other sites More sharing options...
Daniel0 Posted April 18, 2008 Share Posted April 18, 2008 The query probably failed. Quote Link to comment https://forums.phpfreaks.com/topic/101720-solved-help-retrieving-data/#findComment-520429 Share on other sites More sharing options...
cs1h Posted April 18, 2008 Author Share Posted April 18, 2008 Sorry, I'm not very good at php. What do you mean by The query probably failed. Thanks, Colin Quote Link to comment https://forums.phpfreaks.com/topic/101720-solved-help-retrieving-data/#findComment-520433 Share on other sites More sharing options...
Daniel0 Posted April 18, 2008 Share Posted April 18, 2008 That there was an error in your query. It seems to be this part: $sql2 = "SELECT * FROM ac_users WHERE username=$email"; Unless the username is numeric, you'll have to enclose the value in quotes, i.e. $sql2 = "SELECT * FROM ac_users WHERE username='$email'"; Quote Link to comment https://forums.phpfreaks.com/topic/101720-solved-help-retrieving-data/#findComment-520440 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.