Jump to content

[SOLVED] Query problems


solon

Recommended Posts

Hey guys this is a bit complicated but i ll try to explain as good as i can.

 

I have a table with lets say the following values:

 

type

value

something

something2

1

111

something

something2

 

2

222

something

something2

 

3

333

something

something2

.....

....

......

..........

1000

1010101010

something

something2

 

Instead of displaying the values using

$qry = mysql_query("select * from ...");
$row = mysql_fetch_array($qry);
echo $row[type];

i want to access the values of field 'type' , like:

$qry = mysql_query("select * from ...");
$row = mysql_fetch_array($qry);
echo $row[1];
echo $row[2];
echo $row[1000];

and actually display the values of 'value' , 'something', 'something2'

 

I hope you get my point,

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/137706-solved-query-problems/
Share on other sites

<?php
$qry = mysql_query("select * from ...");
while ($row = mysql_fetch_assoc($qry)) {
     $types[] = $row['type'] . ", " . $row['value'] . ", " . $row['something'] . ", " . $row['something2'];
}

$cnt = count($types);
for ($i=0; $i<$cnt; $i++) {
    echo $type[$i] . "<Br />";
}
?>

 

Should do the trick.

 

Or without the for loop:

<?php
$qry = mysql_query("select * from ...");
while ($row = mysql_fetch_assoc($qry)) {
     echo $row['type'] . ", " . $row['value'] . ", " . $row['something'] . ", " . $row['something2'] . "<br />";
}

?>

Not a problem.

 

Just remember

<?php
$qry = mysql_query("select * from ...");
while ($row = mysql_fetch_assoc($qry)) {
     echo $row['type'] . ", " . $row['value'] . ", " . $row['something'] . ", " . $row['something2'] . "<br />";
}

?>

 

Is pretty much the basis for looping through query data.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.