Results 1 to 6 of 6

Thread: [RESOLVED]Replicate Mysql Results

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Question [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

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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 ?>

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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?

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    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.

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Replicate Mysql Results


  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    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
  •  



Click Here to Expand Forum to Full Width