Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.