• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Need to load in browser's memory ALL values for ALL the 50 rows of a SELECT * FROM LIMIT 50 Query

I have a query that should be like this

$RESULTS = 50;

SELECT column1,column2,column3..etc..column10  FROM PRODUCTS LIMIT ' .$RESULTS;

And i need to save ALL values for ALL the Rows into ARRAYs (the number of the ROWs to save in memory is equal to $RESULTS)


Thank You
0
fario
Asked:
fario
  • 7
  • 7
1 Solution
 
Ray PaseurCommented:
You can use the $_SESSION array to hold this information.  Use session_start() at the top of all pages, and you can have this information available from page to page.
0
 
farioAuthor Commented:
But how can i store the values in the SESSION array ? Can someone show me a loop to obtain this ?

Anyway i don't need to use those information on a different page,
so maybe should i use several "standard" PHP arrays ?
0
 
Ray PaseurCommented:
Code something like this...
<?php // RAY_temp_db_2_session.php
session_start();
 
$results = 50;
$sql = "SELECT column1,column2,column3 ...ETC... column10 FROM PRODUCTS LIMIT $results";
$res = mysql_query($sql);
if (!$res) die(mysql_error());
 
while ($row = mysql_fetch_assoc($res))
{
   $_SESSION["db_data"][] = $row;
}

Open in new window

0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
Ray PaseurCommented:
Let me ask a different question... Why?  What advantage are you trying to obtain by doing this?  There may be a better way to achieve the same result.
0
 
farioAuthor Commented:
I need to avoid to make 50    SELECT * FROM   queries inside the same page (i'm creating 50 different little flash files; each one reads some parameters PHP will pass to create a different flash animation)

I have 50 DIVs like the following:
<div id="news02">
<?  IF I CAN'T READ ALL THE 50 ROWS IN JUST ONE QUERY, IN THIS PHP SPACE EACH DIV HAVE TO QUERY THE DB TO FIND THE PARAMETERS RELATED TO THE FOLLOWING FLASH FILE   ?> 
        <p>
        <a href="http://get.adobe.com/it/flashplayer" target="_blank">Installare Adobe Flash</a> <a href="https://www.google.com/adsense/support/bin/answer.py?hl=it&answer=12654" target="_blank">e/o attivare Javascript.</a>
        </p>
        </div>
        <script type="text/javascript">
        // <![CDATA[
        var so = new SWFObject("swf/novita/novita.swf", "news02", "180", "210", "9", "#FFFFFF");
        so.addParam("wmode", "transparent");
        so.addParam("movie", "swf/novita/novita.swf");
        so.addParam("quality", "high");
        so.addParam("scale", "noscale");
===>    so.addParam("FlashVars", "<?=PHP SENDS PARAMETERS HERE   ?>"); <===
        so.write("news02");
        // ]]>
        </script>       

Open in new window

0
 
farioAuthor Commented:
So with the   $_SESSION["db_data"][] = $row;  line i can append ALL the results to the same $_SESSION array ?
0
 
Ray PaseurCommented:
Yes, each $row from the data base will be present in $_SESSION["db_data"] and you can find them like this

foreach ($_SESSION["db_data"] as $row)
{
   var_dump($row);
}
0
 
Ray PaseurCommented:
I think you can do the SELECT... LIMIT 50 and then iterate over the results set, creating the flash files as you do the iteration.  Each of the flash file elements might be stored in an array, then at the end of the iterator, you can go over the array to produce the HTML.
0
 
farioAuthor Commented:
How can i retrieve the values of the $_SESSION["db_data"] stored in the query's row #3

( for example )

How to access to the column1,column2,column3 ...ETC... column10 values of the third Row returned by MySQL ?

Thank You
0
 
Ray PaseurCommented:
Try this for row 3.  Arrays number from zero, query results number from 1.

$row3 = $_SESSION["db_data"][2]

To see the contents of $row3, use this:
var_dump($row3);

You will see that it is an associative array.  The array keys are the column names from the data base table.  The array values are the values in that row of the data base table.

HTH, ~Ray
0
 
farioAuthor Commented:
So i have to use this PHP code before every flash DIV ?

$row1 = $_SESSION["db_data"][0];
$price1= $row1['column1'];
$name1 = $row1['column2'];

$row2 = $_SESSION["db_data"][1];
$price2 = $row2['column1'];
$name2 = $row2['column2'];

$row3 = $_SESSION["db_data"][2];
$price3 = $row3['column1'];
$name3 = $row3['column2'];

and so on..  

is this correct
?


0
 
farioAuthor Commented:
Ok it works thank You
0
 
Ray PaseurCommented:
Rather than using all those individual statements, you might want to use an iterator, such as foreach() to step through the array.  Smaller and more generalized code - less risk of typos.

foreach ($_SESSION["db_data"] as $row)
{
   $price= $row['column1'];
   $name = $row['column2'];
/* PROCESS NAME AND PRICE DATA HERE */
}
0
 
farioAuthor Commented:
Hi

are You sure the iterator is correct ?
it doesn't pass any value to the vars

Thank you
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now