jimmi8 Posted December 29, 2006 Share Posted December 29, 2006 Hi,I have this problem that i dont know how to work out as im still very new to php/sql. I have a script that queries my database and pulls out information about a blog entry ( title, body text, author, date submitted). All this info is generated from one table ( and yes the author column is creating redundant data but ill sort that out soon)I have another table in my db thats for categories. My first query gets the category id fine and assigns it to a variable ($cat). Now the problem question i have is how to incorportae the query ive made below with the join. Can i include it somehow in the query above and do both at once or what? ive never made a call to two databases in the same instance before. Could anyone suggest a good way to do this? As the code is now all thats getting printed out( in green) is resource1d#4???!?!?![code]<ul> <?php require_once ('mysql_connect.php'); // Connect to the db. $sql = "SELECT * FROM entries ORDER BY date_submitted DESC LIMIT 5";$query = mysql_query($sql);echo $query;while ($row = mysql_fetch_array($query)) { $title = $row['title']; $body = $row['body']; $author = $row['author_id']; $date = $row['date_submitted']; $cat = $row['category_id']; ?><li><?php echo $title; echo $date; echo $body; ?></li><p style="red"><?php echo $author; ?></p><p style="color: red;"><?php echo $cat; ?></p><?php}?><?php$sql = "SELECT category FROM categories Where categories.category_id = $cat";$result = mysql_query($sql);?></ul><p style="color: green;"><?php echo $result; ?></p>[/code] Link to comment https://forums.phpfreaks.com/topic/32165-how-can-i-construct-this-call-to-my-database/ Share on other sites More sharing options...
Orio Posted December 29, 2006 Share Posted December 29, 2006 [code]$result = mysql_result(mysql_query($sql), 0, "category_id");[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/32165-how-can-i-construct-this-call-to-my-database/#findComment-149291 Share on other sites More sharing options...
jimmi8 Posted December 29, 2006 Author Share Posted December 29, 2006 Hi orio,Thanks for the reply. I tires the code you gave but it didnt work. i got this error: Warning: mysql_result() [function.mysql-result]: category_ID not found in Mysql result index 5 in.....my doc root...on line 41.I also need the query to kinda be in the the the above while loop somehow because im spitting out 5 articles so i would need the category query to be tied in so that i got a result for each articleAny ideas?!? Link to comment https://forums.phpfreaks.com/topic/32165-how-can-i-construct-this-call-to-my-database/#findComment-149293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.