Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/101720-solved-help-retrieving-data/
Share on other sites

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'";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.