cs1h Posted April 25, 2008 Share Posted April 25, 2008 Hi, I have a a script that gathers information from three different databases and displays the data in the same table, it is designed top do this for three times. The first database gets the code to access the second database, the second database is where most the information is stored and a piece of information from the second database is whats used to search the third on for the information that is needed. The problem is that its not getting the results from the third database, but I have checked to see that it is getting the required information from the second database to search for. The code is <?php mysql_connect("localhost","xxx","xxx"); mysql_select_db("xxx") or die("Unable to select database"); $art = $_GET['id']; $sql = "SELECT * FROM items WHERE id=$art"; $result = mysql_query($sql)or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo "No results please try a different <a href=asearch.html>search</a>."; } else { while($row = mysql_fetch_array($result)) { $code1 = $row['code1']; $code2 = $row['code2']; mysql_close(); } } mysql_connect("localhost","yyy","yyy"); mysql_select_db("yyy") or die("Unable to select database"); $sql = "SELECT * FROM `$code1 by $code2` ORDER BY id DESC LIMIT 3"; $result = mysql_query($sql) or die(mysql_error()); $num_rows = mysql_num_rows($result); if($num_rows == 0) { echo ""; } else { $CommAuth = array(); $Comment = array(); $horde = array(); $title = array(); while($row = mysql_fetch_assoc($result)) { $CommAuth[] .= $row['name']; $Comment[] .= $row['message']; $horde[] .= $row['horde']; $title[] .= $row['title']; } } mysql_close(); mysql_connect("localhost","zzz","zzz"); mysql_select_db("zzz") or die("Unable to select database"); $sql2 = "SELECT * FROM ac_users WHERE username='$title' LIMIT 3"; $result2 = mysql_query($sql2)or die(mysql_error()); $num_rows2 = mysql_num_rows($result2); if($num_rows2 == 0) { echo "No results please try a different <a href=reports.php>search 2</a>."; } else { $CommAvatar = array(); while($row2 = mysql_fetch_array($result2)) { $CommAvatar[] .= $row2['avatar']; } } $count = 0; foreach ($CommAuth as $value){ print "<div id=\"comment\"> <img src=\"/avatar/{$CommAvatar[$count]}\" width=\"56\" height=\"56\" class=\"comment_photo\" /> <div id=\"comment_header\"><span class=\"comment_author\"> {$value} </span><span class=\"comment_wrote\">wrote...</span><span class=\"comment_stars\"><img src=\"stars_5.png\"/></span></div> <div class=\"comment_text\">{$Comment[$count]}</div> <div id=\"comment_footer\"><span class=\"comment_delete\">Report | Comment on {$value} Profile | Message {$value}</span></div> </div>"; $count++; } ?> If anyone can help, it will much appreciated because this has been annoying me for weeks now. Thanks, Colin Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/ Share on other sites More sharing options...
zenag Posted April 25, 2008 Share Posted April 25, 2008 can u show ur database structure ....since u have assigned $title as array u have to implode $title and then continue ur search in third database. Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-526973 Share on other sites More sharing options...
cs1h Posted April 25, 2008 Author Share Posted April 25, 2008 The database structure is, CREATE TABLE `ac_users` ( `id` int(11) NOT NULL auto_increment, `username` varchar(250) NOT NULL, `password` varchar(250) NOT NULL, `name1` varchar(250) NOT NULL, `name2` varchar(250) NOT NULL, `email` varchar(250) NOT NULL, `horde` varchar(250) NOT NULL, `avatar` varchar(255) NOT NULL, `origin` varchar(250) NOT NULL, `joined` timestamp NOT NULL default CURRENT_TIMESTAMP, `Code_1` varchar(255) NOT NULL, `Code_2` varchar(255) NOT NULL, `Access_level` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1343 ; How would I go about imploding $title? Thanks, Colin Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-526983 Share on other sites More sharing options...
zenag Posted April 25, 2008 Share Posted April 25, 2008 about ur $title value what does it echo... Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-526989 Share on other sites More sharing options...
zenag Posted April 25, 2008 Share Posted April 25, 2008 r u trying to search in third database with three or more username values.? Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-526990 Share on other sites More sharing options...
cs1h Posted April 25, 2008 Author Share Posted April 25, 2008 It echos an email address, I'm not sure what you mean by r u trying to search in third database with three or more username values.? But if you mean what I think you mean it is meant to get a different result for each of the results from the second database. Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-526995 Share on other sites More sharing options...
cs1h Posted April 25, 2008 Author Share Posted April 25, 2008 Hi, Does anyone know that since the result "$title" (which is the search criteria for the third database) is an email address could it be causing the problem of no search results? Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-527081 Share on other sites More sharing options...
zenag Posted April 26, 2008 Share Posted April 26, 2008 why do u assign array to $title ...try it like while($row = mysql_fetch_assoc($result)) { $CommAuth= $row['name']; $Comment = $row['message']; $horde = $row['horde']; $title= $row['title']; } } Link to comment https://forums.phpfreaks.com/topic/102880-help-getting-search-results/#findComment-527569 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.