|
-
Dec 6th, 2006, 11:24 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED]Replicate Mysql Results
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
Last edited by zalez; Dec 7th, 2006 at 08:52 PM.
Reason: RESOLVED
-
Dec 6th, 2006, 11:49 PM
#2
Re: Replicate Mysql Results
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 Code:
<?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 } ?>
-
Dec 7th, 2006, 12:28 AM
#3
Re: Replicate Mysql Results
Don't quite follow.
Do you want to create an object representing a record set that can be serialised into an INSERT statement?
-
Dec 7th, 2006, 08:30 PM
#4
Thread Starter
Hyperactive Member
Re: Replicate Mysql Results
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.
-
Dec 7th, 2006, 08:38 PM
#5
Re: Replicate Mysql Results
-
Dec 7th, 2006, 08:52 PM
#6
Thread Starter
Hyperactive Member
Re: Replicate Mysql Results
Both you of you were exactly right! Thank you soooo much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|