Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Mithras

Mithras Avatar

****
Studio Member

600


July 2006
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 :P), 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!

lucifer said:
"Behold: me! I have authority in this building."

Moose

Moose Avatar

****
Senior Member

449


August 2005
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. :P
Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
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:
:P Yeah, I'll get right on that... right after I learn to fly.

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
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

Moose

Moose Avatar

****
Senior Member

449


August 2005
$sql = mysql_query("SELECT * FROM `table` WHERE `id` = '$row_id' LIMIT 1);

Forgot an ending quote. :P
Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
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:
:P Yeah, I'll get right on that... right after I learn to fly.

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
just testing you moosey :P

Mithras

Mithras Avatar

****
Studio Member

600


July 2006
o...k....

That went right over my head. I'll read some of those tutorials that you posted, phoenix, and see if I can figure it out :P


Support Rob Scuderi, the #1 Penguins Defender!

lucifer said:
"Behold: me! I have authority in this building."

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
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?

Moose

Moose Avatar

****
Senior Member

449


August 2005
It also helps to have a good understanding of JavaScript before PHP. Knowing JavaScript helped me cut a lot of corners. :P
Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
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:
:P Yeah, I'll get right on that... right after I learn to fly.

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
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).

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
cddude229 said:
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

Mithras

Mithras Avatar

****
Studio Member

600


July 2006
Oh... I thought that I saw .length on a PHP tutorial :P

This may take a while...


Support Rob Scuderi, the #1 Penguins Defender!

lucifer said:
"Behold: me! I have authority in this building."

Llanilek

Llanilek Avatar
Former Elite Mod

****
Dedicated Studio Member

931


October 2005
well its taken me two years to get where i am now :) lol

Sunshine

Sunshine Avatar
You are my sunshine

***
Dedicated Member

147


August 2006
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
I My Boyfriend

In his hand
the pen that lied
this is how
the author died


¿Quién te cortó las alas mi ángel? ¿quién te arrodillé para humillarte?

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
Artemis, I hope to got you validated $code_cat.... :P

Mithras

Mithras Avatar

****
Studio Member

600


July 2006
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!

lucifer said:
"Behold: me! I have authority in this building."

newBookmarkLockedFalling