Click to See Complete Forum and Search --> : [RESOLVED]Replicate Mysql Results
zalez
Dec 6th, 2006, 10:24 PM
How would I make an array that would act just like an array returning mysql results. ex:
$myrow[thumb1]
$myrow[thumb2]
ect.
ect.
And what I want to do is if there is now results sent back, then I would like to populate the array by hand.
Any and all help is appreciated :)
kows
Dec 6th, 2006, 10:49 PM
I'm not quite sure I understand what you want to do.. but, this might be what you're looking for? (in this example, I assume you're collecting thumbnails.. so I collected thumbnails from a table with the thumbnail filename and the fullsize filename)
<?php
$sql = "SELECT thumb, fullsize FROM thumbs WHERE somefield='something' LIMIT 25";
$query = mysql_query($sql);
if(mysql_num_rows($query) == 0){
//build array by hand
$myrow = array("thumbnail1.jpg" => "fullsize1.jpg",
"thumbnail2.jpg" => "fullsize2.jpg");
}else{
while($array = mysql_fetch_array($query))
$myrow[$array['title']] = $array['filename'];
}
//display these thumbnails
foreach($myrow as $thumbnail => $fullsize){
?>
<b><?php echo $fullsize; ?></b><br />
<a href="./images/<?php echo $fullsize; ?>"><img src="./images/<?php echo $thumbnail; ?>" /></a><br /><br />
<?php } ?>
penagate
Dec 6th, 2006, 11:28 PM
Don't quite follow.
Do you want to create an object representing a record set that can be serialised into an INSERT statement?
zalez
Dec 7th, 2006, 07:30 PM
Sorry I didn't explain it clear. What I am doing is I query a db that gathers thumbnail paths, and to keep existing code intact without having to write a seperate function and update my code, if there is nothing returned from the query, i want to populate an array that acts just as if it was a return result of the query.
pseudo:
$myrow is results from query.
If $myrow equals nothing, (no results found)
populate $myrow to act as if there were results returned.
so no matter what when i use $myrow[thumb1] or $myrow[thumb2] I will get something other than an empty string.
penagate
Dec 7th, 2006, 07:38 PM
array_walk() (http://au3.php.net/array_walk)?
zalez
Dec 7th, 2006, 07:52 PM
Both you of you were exactly right! :) Thank you soooo much.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.