Jump to content

Recommended Posts

I have the following code :

 

$rs_brass = mysql_query("SELECT * FROM the_brass");
$row_brass = mysql_fetch_array($rs_brass);
echo $row_brass["image"]; //this echos out [b]some.jpg[/b]

 

however suppose i want to see the value of image of the 4th recordset..i tried:

 

echo $row_brass["image"][4];

 

but this doesnt seem to do the trick... any feedback/help appreciated... thanks

 

 

array start from 0 not 1

 

example

 

<?php

$image=array("a.jpg","b.jpg","c.jpg","d.jpg");


echo " ".$image[3]."";

?>

 

 

example 2

<?php

$image=array("image1"=>"a.jpg","image2"=>"b.jpg","image3"=>"c.jpg","image4"=>"d.jpg");


echo " ".$image['image4']."";

?>

thanks for your help.. I have 10 records in my database, so should'nt

 

echo $row_brass["image"][1];

 

still show the value of the whats in the image column? it doesnt show it.. do u know the correct syntax for pointing to a record in the recordset?

 

for e.g

 

echo $row_brass["image"]; 

 

shows the value in the first row of the image column i.e some.jpg

 

so shouldnt  echo $row_brass["image"][1] show the value in the second row of the image column in the database?

 

thanks for your help mate .. but you are hardcoding your array.. im trying to get the value from a recordset, so your method does'nt really aid me in this instance .. i just need to know how to point to a particular record in the recordset and retrieve the value of a particular column of that record..

 

echo $row_brass[4]  doesnt give me any proper value as how will it know the column I am trying to target? there are 5 different columns...

 

thanks for your help anyway...  :)

 

 

 

 

here an example how the array acts in and out off a loop

<?php

$image=array("a.jpg","b.jpg","c.jpg","d.jpg");


foreach($image as $gotu){


echo " <br> in a loop but wrong result >>> {$gotu[3]} <br><br>";


echo " <br> <br> in a loop  correct result>>> {$gotu} <br><br>";

}

echo " <br> out off the loop {$image[3]}";

?>

this will get the array of number 4 but array start at 0 so array 3 is correct for the 4th info.

$rs_brass = mysql_query("SELECT * FROM the_brass");

echo $row_brass[3]; //this echos out some.jpg

 

 

sorry

<?php
$rs_brass = mysql_query("SELECT * FROM the_brass");
echo $rs_brass[3]; //this echos out some.jpg 
?>

thanks but i think we are on different tracks at the moment  :-\ ... i know the concepts of arrays... if you are able to show me using this terminology and without creating your own array and without loops ( we should be able to target an element of an array directly without any loops, if we know the index of the array required) that would greatly help:

 

$rs_brass = mysql_query("SELECT * FROM the_brass");

$row_brass = mysql_fetch_array($rs_brass);

 

how do we target directly the 4th record and its value in the image column... thats all i need...

 

theres a specific point on the page where i always just need to show the image of the fourth record... no other records will ever be added or deleted to the table...

 

<img src="<?php echo "image from fourth record" ?>" />

 

$rs_brass[4] echos out some.jpg of the first record  ....

 

but then how do i echo it out for the second record? I tried $rs_brass[1][4] but that doesnt work...

I could be wrong but i believe if i have an array of records and I know the index number of the record i want, then I should be able to retrieve it directly from the array... anyway thanks for your help dude..maybe we'll get some other replies which can help us further..

look in the database you got the field as image, and there many image names under the name image.

 

when you loop with your $rec['image']; you get all the info in the image database field.

 

now if you needed to use one off them image names via the loop your need to call it via it name.

 

so example

 

<?php

if($rec['image']=="a.jpg"){

//do somethink

}
?>

you can also use the array with no loop like this

<?php
$rs_brass = mysql_query("SELECT * FROM the_brass");
echo $rs_brass[3]; //this echos out some.jpg 
?>

That saying that array number 3 is the data you want,

there no other way.

becouse alll the images are under the database field of image so the loop makes you call it via it name but the array let you call it by it array position not using the loop.

 

 

Hi, you could try this if you know which record it is specifically that you wanted:

 

<?php
$rs_brass = mysql_query("SELECT * FROM the_brass ORDER BY `key` LIMIT 3,1");
$row_brass = mysql_fetch_array($rs_brass);
echo $row_brass["image"]
?>

 

that would then get the 3rd record

 

Hope that helps / works ;)

Hi, you could try this if you know which record it is specifically that you wanted:

 

$rs_brass = mysql_query("SELECT * FROM the_brass ORDER BY `key` LIMIT 3,1");
$row_brass = mysql_fetch_array($rs_brass);
echo $row_brass["image"]
?>

 

that would then get the 3rd record

 

Hope that helps / works ;)

 

So then he would have to do a query every time he wanted to retrieve a record from the database.  Just use a multi-dimensional array.

OR, if you want to keep all of the data,

<?php
$rs_brass = mysql_query("SELECT * FROM the_brass");

// do a loop to gather all results
for($i=0;$row_brass = mysql_fetch_array($rs_brass);$i++) {

   // save data into large array
   $array[$i] = $row_brass["image"];
   // If it is row 3 (item #4, remember it starts with 0)
   if($i == 3) 
      echo $row_brass['image'];
}
print_r($array); // show full array
?>

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.