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
Post
by Dale » Sat Feb 14, 2004 9:13 pm
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 9:16 pm
$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 » Sat Feb 14, 2004 9:25 pm
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
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 9:27 pm
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 » Sat Feb 14, 2004 9:46 pm
Arrr... its saying
Query was empty
but where its pointing to isnt empty in the database :z
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 9:49 pm
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 » Sat Feb 14, 2004 9:56 pm
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());
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 9:57 pm
$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 » Sat Feb 14, 2004 10:01 pm
^ 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)
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 10:04 pm
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 » Sat Feb 14, 2004 10:12 pm
eh?
Confusing.... me gets a coffee... right..
forumid is the name of a row in the df_threads table in the database.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 10:14 pm
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 » Sat Feb 14, 2004 10:18 pm
id is from the address viewforum.php?fid=WHAT EVER NUMBER...
shoot its not ID it suppose to be FID....
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Sat Feb 14, 2004 10:20 pm
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 » Sat Feb 14, 2004 10:25 pm
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