Show certain things in certain $id

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Show certain things in certain $id

Post 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 ;)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$result = mysql_query("select * FROM df_threads WHERE fid = $forumid order by id desc");

</whoosh> ;)
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Arrr... its saying
Query was empty
but where its pointing to isnt empty in the database :z
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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?
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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());
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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());
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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) :)
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Then $forumid is undefined/not set.
Where's that value coming from .. or where do you set/define it?
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

eh?

Confusing.... me gets a coffee... right..

forumid is the name of a row in the df_threads table in the database.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ;)
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

id is from the address viewforum.php?fid=WHAT EVER NUMBER...

shoot its not ID it suppose to be FID....
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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 ;)
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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
Post Reply