simple db help for php row

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

Moderator: General Moderators

Post Reply
vaska
Forum Newbie
Posts: 4
Joined: Mon Aug 19, 2002 9:47 am

simple db help for php row

Post by vaska »

sorry...i've been stuck with duties dealing with a php/mysql setup...but i have not knowledge of these things...well, not much...

what i need to do is very simple...

with a link such as http://www.??????.com/webpage.php?id=2 or 3 or whatever...

i just need the page to return the correct row of information and insert it into the page...that's it...but i'm clueless...

i have connected to the database though...and can extract info from the db...but, only from the first record...i can't get other rows of information?

i've been searching all day...can anybody help?

thanks...jv
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What does your code look like thus far?

Mac
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Code: Select all

$sql = SELECT * FROM yourTable WHERE id = ".$_GETїid]
Then....

Code: Select all

$temp = mysql_query($sql);
while($result = mysql_fetch_array($temp))
ї
  echo $resultїCOLUMN NAME];
  echo $resultїCOLUMN NAME2];
]
To access the diffrent column change the COLUMN NAME and COLUMN NAME2 etc.
vaska
Forum Newbie
Posts: 4
Joined: Mon Aug 19, 2002 9:47 am

Post by vaska »

hi!

looks like this...sequence is acting as ID (i didn't set that up)...

thanks mucho for any input...jv


<?
mysql_connect("localhost"," "," ");
mysql_select_db("reviews");

$query = mysql_query("SELECT * FROM review where sequence='$sequence' " ) or die ("Unexpected error for MySQL database [1b]");
$row = mysql_fetch_array($query);

?>
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

???
vaska
Forum Newbie
Posts: 4
Joined: Mon Aug 19, 2002 9:47 am

yep

Post by vaska »

might look funny...but it's doing what i want it to do...but i know it's not correct...jv
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

Nothing wrong with that just put in the WHILE part

while($row=mysql_fetch_array($query)){
print "My first column is ".$row[COLUMN_NAME_HERE];
...
}

On another point the die statement after your SQL is probably not much use unless you have completely screwed up the SQL syntax, which you haven't or the table gets deleted, so it will never be called. It is probably better to place it at the connect statement.
vaska
Forum Newbie
Posts: 4
Joined: Mon Aug 19, 2002 9:47 am

column name?

Post by vaska »

why would i want column information...

i want one record...one row of information...

maybe i explained it wrong...probably...

i know it's not the best...it's working...so far...

thanks...jv
conthox
Forum Commoner
Posts: 39
Joined: Tue Jun 25, 2002 1:44 pm
Location: Sweden

Post by conthox »

If you print out all columns - you got one row!
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Re: column name?

Post by mikeq »

vaska wrote:why would i want column information...

i want one record...one row of information...

maybe i explained it wrong...probably...

i know it's not the best...it's working...so far...

thanks...jv
The print "My first column is ".$row[COLUMN_NAME_HERE]; was an example, sorry did you want us to write the whole thing for you, give me a couple of weeks and wait by your email.
Post Reply