Page 1 of 2
Show certain things in certain $id
Posted: Sat Feb 14, 2004 9:13 pm
by Dale
ok 2nd and final thing tonight
When i access
viewforum.php im using this code:
Code: Select all
$result = mysql_query("select * from df_threads order by id desc");
Which displays
ALL the entries in df_threads table in newest post order. But now i want to know how to make it so if i access forumid 2 then it shows the threads for that room... i've tried
Code: Select all
$result = mysql_query("select WHERE $fid = $forumid from df_threads order by id desc");
and you can see im a total n00b at mysql.. that probably isnt even a working command... and it isnt.. gives me the error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\app serv\www\forum\viewforum.php on line 23
So could anyone help???
* I hear markl999 wooshing in

Posted: Sat Feb 14, 2004 9:16 pm
by markl999
$result = mysql_query("select * FROM df_threads WHERE fid = $forumid order by id desc");
</whoosh>

Posted: Sat Feb 14, 2004 9:25 pm
by Dale
Hmmm...
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\app serv\www\forum\viewforum.php on line 23
Posted: Sat Feb 14, 2004 9:27 pm
by markl999
The do the same technique again.
$query = "SELECT ...etc..etc..";
echo $query; //for debugging
mysql_query($query) or die(mysql_error());
Should tell you what's up.
Posted: Sat Feb 14, 2004 9:46 pm
by Dale
Arrr... its saying
Query was empty
but where its pointing to isnt empty in the database :z
Posted: Sat Feb 14, 2004 9:49 pm
by markl999
Query was empty suggests you've done something like mysql_query($query) where $query isn't defined.
What does you code look like?
Posted: Sat Feb 14, 2004 9:56 pm
by Dale
This...
Code: Select all
// Helped By markl999
$result = mysql_query("select * FROM df_threads WHERE fid = $forumid order by id desc");
echo $result; //for debugging
mysql_query($result) or die(mysql_error());
Posted: Sat Feb 14, 2004 9:57 pm
by markl999
$result = "select * FROM df_threads WHERE fid = $forumid order by id desc";
echo $result; //for debugging
mysql_query($result) or die(mysql_error());
Posted: Sat Feb 14, 2004 10:01 pm
by Dale
^ Now that code you just gave me says this:
select * FROM df_threads WHERE fid = order by id descYou have an error in your SQL syntax near 'order by id desc' at line 1
(Looks like its gonna be a long night)

Posted: Sat Feb 14, 2004 10:04 pm
by markl999
Then $forumid is undefined/not set.
Where's that value coming from .. or where do you set/define it?
Posted: Sat Feb 14, 2004 10:12 pm
by Dale
eh?
Confusing.... me gets a coffee... right..
forumid is the name of a row in the df_threads table in the database.
Posted: Sat Feb 14, 2004 10:14 pm
by markl999
forumid is the name of a row in the df_threads table in the database.
Ok, then your query needs to be like :
SELECT * FROM df_threads WHERE forumid=$id ORDER BY id DESC" ... how and where you set $id i don't know...but it needs to be the id of the forum you want to select from

Posted: Sat Feb 14, 2004 10:18 pm
by Dale
id is from the address viewforum.php?fid=WHAT EVER NUMBER...
shoot its not ID it suppose to be FID....
Posted: Sat Feb 14, 2004 10:20 pm
by markl999
So ...
"SELECT * FROM df_threads WHERE forumid=".$_GET['fid']." ORDER BY id DESC" seems to be the one methinks. Presuming id is also a column in your db.. if not, leave the order by id out or order by some column that exists

Posted: Sat Feb 14, 2004 10:25 pm
by Dale
Using
Code: Select all
$result = "SELECT * FROM df_threads WHERE forumid=".$_GET['fid']." ORDER BY id DESC";
echo $result; //for debugging
mysql_query($result) or die(mysql_error());
i get:
SELECT * FROM df_threads WHERE forumid= ORDER BY id DESCYou have an error in your SQL syntax near 'ORDER BY id DESC' at line 1
using
Code: Select all
$result = "SELECT * FROM df_threads WHERE forumid=".$_GET['fid']."";
echo $result; //for debugging
mysql_query($result) or die(mysql_error());
i get:
SELECT * FROM df_threads WHERE forumid=You have an error in your SQL syntax near '' at line 1