|
I'm trying to make a comment system using MySQL (I know, I'm a noob at this, but I figure the best way to learn is to start a project ), and what I need to know, is how do I specify a certain row? Like, if I have this: $name = mysql_query('SELECT name FROM commentTable') but I need to specify the row. Would that just return an array, then I use $name[0] for the first one, then $name[$name.length()-1], for the last?
|
Support Rob Scuderi, the #1 Penguins Defender!
"Behold: me! I have authority in this building."
|
|
|
|
I like to use * and get an associative array I can work with from mysql_fetch_array but that's just me. Connect and try something like this: $lequery = mysql_query("SELECT * FROM commentTable WHERE id='$idnum'"); while($therow = mysql_fetch_array($lequery)){ $name = $therow['name']; $message = $therow['message']; // Etc. but this grabs a row yay! And stores our crap in variables we can shoot out! } Then close your connection.
|
Greg says: Coding music... Greg says: Hmm... Greg says: I wouldn't rule it out. Chris 3.0 [New features? Yes.] says:
Greg says: If you think about machine code it's a bunch of 1s and 0s Chris 3.0 [New features? Yes.] says: Anything is possible. Greg says: Yeah try to code Metallica Chris 3.0 [New features? Yes.] says: Yeah, I'll get right on that... right after I learn to fly.
|
|
|
|
ok i think your getting js and php confused here... you have to use the tables primary key function to really be able to grab a specific row... usually every table has a row id header which is +1 each row... using this statement can grab the row id you are after $row_id = 2; $sql = mysql_query("SELECT * FROM `table` WHERE `id` = '$row_id' LIMIT 1");
but then you'd have to somehow grab the info from that table... i use mysql_fetch_object(); but there are a few others.. some people don't recommend fetch_object but you can also use mysql_fetch_array();mysql_fetch_row();then use a while loop to get the info while($r=mysql_fetch_object($sql)){ echo $r->rowheader; }
Last Edit: Sept 5, 2006 1:00:29 GMT by Llanilek
|
|
|
|
|
|
just testing you moosey
|
|
|
|
|
|
you see thats why you really shouldn't jump in at the deep end to learn php unless you have some basic knowledge of either flat file or mysql.
let us no how it goes yeh?
|
|
|
|
|
|
JS is method based, PHP is more function based (before OOP anyway).
Also, .length isn't a property for PHP arrays. Its count($array) (if I remember correctly).
|
|
|
|
|
JS is method based, PHP is more function based (before OOP anyway). Also, .length isn't a property for PHP arrays. Its count($array) (if I remember correctly). thats the reason why i said he was confusing php and js
|
|
|
|
|
|
well its taken me two years to get where i am now lol
|
|
|
|
|
Well, for my code database, I just used:
$query="SELECT * FROM Codes WHERE category='$code_cat' ORDER BY code_name"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; $final_code = '<ul>';
while($i<$num){ $db_url= mysql_result($result,$i,"thread_url"); $db_name= mysql_result($result,$i,"code_name"); $i++; }
It'll return everything that fits the specification. If you use WHERE field='$field', you'll probably get only one result.
~Artemis
|
|
|
|
|
Artemis, I hope to got you validated $code_cat....
|
|
|
|
|
Sorry to bump this, but I just started trying to do this again, and I have one serious question...
How do I create the database? Do I just go into my Admin Panel on the server, and physically create it, or do I use some fancy code?
|
Support Rob Scuderi, the #1 Penguins Defender!
"Behold: me! I have authority in this building."
|
|
|