View Full Version : Problem with getting data from mysql
jaffyy
11-17-2007, 09:59 PM
I have this problem when i try to get my data from the mysql db -->
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hosting/l2/web/index.php on line 142
This is my script:
<?php
include 'inc/config.php';
include 'inc/mysql.php';
$query = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC".
"SELECT user_id FROM phpbb_users";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<a href='forum/viewtopic.php?t={$row['topic_id']}'> {$row['topic_title']} <b>by</b> <a href='forum/profile.php?mode=viewprofile&u={$row['user_id']}'> {$row['topic_poster']}<br>";
}
include 'inc/cmysql.php';
?>
djr33
11-17-2007, 11:15 PM
$query = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC".
"SELECT user_id FROM phpbb_users";
//Becomes
$query = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESCSELECT user_id FROM phpbb_users";
You can perform two operations in one query by separating the lines by a semicolon:
SELECT ...; SELECT ...;
However, this doesn't work properly with PHP as it would return two separate sets of results in one query.
As such, just do one call at a time.
If you do need to make them integrated, you can try it like this:
$a = mysql_query($query1);
$b = mysql_query($query2);
while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) ) {
echo $rowa[1].$rowb[2];
}
jaffyy
11-17-2007, 11:40 PM
thanks i will try it :)
P.S. The first one didnt work i will try the second...
jaffyy
11-18-2007, 09:27 AM
same....
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hosting/l2/web/index.php on line 184
184 line is this:
while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )
tech_support
11-18-2007, 09:32 AM
What's $a and $b?
jaffyy
11-18-2007, 10:09 AM
Its the queries
$query1 = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC";
$query2 = "SELECT user_id FROM phpbb_users";
$a = mysql_query($query1);
$b = mysql_query($query2);
while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )
tech_support
11-18-2007, 10:11 AM
Try:
$query1 = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics LIMIT 10 ORDER BY topic_id DESC";
$query2 = "SELECT user_id FROM phpbb_users";
$a = mysql_query($query1) or die(mysql_error());
$b = mysql_query($query2) or die(mysql_error());
while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )
and output the errors given.
jaffyy
11-18-2007, 10:13 AM
Now i have MySQL error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY topic_id DESC' at line 1
jaffyy
11-18-2007, 10:41 AM
Problem solved syntax fixed ^.^ thanks all
jaffyy
11-18-2007, 12:58 PM
I have another problem... the query for username its not correct ... it shows IDs of usernames only... it dont show the CORRECT THING... im using PHPBB
This is my whole script....
<?php
include 'inc/config.php';
include 'inc/mysql.php';
$query1 = "SELECT topic_id, topic_title, topic_poster FROM phpbb_topics ORDER BY `topic_id` DESC LIMIT 9";
$query2 = "SELECT post_username FROM phpbb_posts";
$a = mysql_query($query1) or die(mysql_error());
$b = mysql_query($query2) or die(mysql_error());
while ( ($rowa = mysql_fetch_assoc($a)) && ($rowb = mysql_fetch_assoc($b)) )
{
echo "<font size=2><a href='forum/viewtopic.php?t={$rowa['topic_id']}'> {$rowa['topic_title']}</a> <font color=grey><b>by</b></font> <a href='forum/profile.php?mode=viewprofile&u={$rowa['topic_poster']}'> {$rowb['topic_username']}</a><br></font>";
}
include 'inc/cmysql.php';
?>
You can see the result only at the index page ----> http://l2.headoff.com (Its not advertising only want to show you!!!)
And it shows latest made TOPICS not POSTS .. i tried to make POSTS but no success ... thanks for trying to help again :)
djr33
11-18-2007, 01:36 PM
I'm guessing you then do another query for that ID in the users table. That's how many forum databases work, anyway.
Using the ID allows for a generic representation (ie, ?user=48), and changing usernames. A user can update their name, or an administrator can, and all instances will be updated, as the ID is just a link to the name field in the users table for that individual user (specified by the ID).
jaffyy
11-18-2007, 01:41 PM
How should this query look like?
SELECT username FROM phpbb_users .... and then???
djr33
11-18-2007, 01:42 PM
Where ID = ...
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.