Jump to content

[SOLVED] help retrieving data


cs1h

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.