Re: [PHP-DB] Site Map and Page-o-mation

2008-11-13 Thread Ron Piggott

Chris I had tried this solution before I e-mailed the list.  It didn't
work, the image filenames are sequential order ( 1.JPG, 2.JPG,
etc.)  

I have simply decided to put the most updated images showing on the
first page of thumbnails by reversing the ORDER BY to have the date
field first and file name second.  

Thanks for your input.

Ron

On Thu, 2008-11-13 at 15:30 +1100, Chris wrote:
 Ron Piggott wrote:
  This doesn't take into account the page - o - mation though.
  
  The query that determines which up to 18 images display on the
  thumbnails page is:
  
  SELECT * FROM photo_gallery_category INNER JOIN photo_gallery_index ON
  photo_gallery_index.photo_gallery_category_reference =
  photo_gallery_category.reference WHERE
  photo_gallery_category.category_name = '$photo_gallery_category' ORDER
  BY photo_gallery_index.filename ASC LIMIT  . ( ($page*18) -18) .  , 18
  
  I see where you are coming from Chris.  What I need to know is from the
  18 images which has the most recent last_update value.  I need the site
  map to match what is being displayed on the thumbnails page.
 
 You can order by two fields.
 
 order by filename asc, last_update_time desc limit ...
 


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Copying Data From One Table To Another Table

2008-11-13 Thread Alice Wei


Hi, 

   I am trying to accomplish a task of which I have to copy the data from one 
table to another. The problem is that whenever I tried to perform the action of 
copying the data through this method, although the data gets copied, it 
performs reiterative copying that causes my program and my server to crash. 

  Here is the code snippet:

  #Empty Temporary Array
  $tmpHolder = array();
  $tmpHolder2 = array();
 
  #Loop through parts list
  foreach ($stringChunk1 As $part) {

#Create a single statement and stuff it in your tmp array
$tmpHolder[]=incidence.name LIKE '%{$part}';  
  }
  foreach ($stringChunk2 As $part2) {

#Create a single statement and stuff it in your tmp array
$tmpHolder2[]=regions.name LIKE '%{$part2}';  
  }

  #Join all the parts together, placing an OR between each element
  $string3= join(' OR ', $tmpHolder);
  $string2= join(' OR ', $tmpHolder2);
  $total=$count_chunk1 * $count_chunk2;

 //Entry a New Query Entry into scenarios table
   $query3=INSERT INTO scenarios VALUES('$scenario_name');
   $result3=mssql_query($query3) or die (The query has failed);
  
   #Search for the Regions and Incidence ID  
   $query_both=SELECT incidence.ID,regions.ID from incidence,regions WHERE 
($string3)AND ($string2); 
   $result_both=mssql_query($query_both) or die (The query has failed);  

  while($row_both = mssql_fetch_array($result_both)) {

   $incidence_id= $row_both[0];
   $region_id= $row_both[1];

 //Enter entry into scenario elements table
//  $query14=INSERT INTO 
scenario_elements(region_id,incidence_id,market,number_sales,number_defer,customer_satisfaction)
//  SELECT 
region_id,incidence_id,market,number_sales,number_defer,customer_satisfaction 
FROM scenario_elements_2,regions,incidence WHERE $string2 AND $string3;
//  $result14=mssql_query($query14) or die (The query has failed);
  

I have to comment out the code snippet above because it creates something like 
3 entries to the database. Could anyone please tell me if this is the error 
I have from my PHP, or is it from my SQL statement? How would I go about fixing 
this issue? 

Thanks in advance. 

Alice


_
All-in-one security and maintenance for your PC.  Get a free 90-day trial!
http://www.windowsonecare.com/purchase/trial.aspx?sc_cid=wl_wlmail

Re: [PHP-DB] Copying Data From One Table To Another Table

2008-11-13 Thread Chris

Alice Wei wrote:


Hi, 

   I am trying to accomplish a task of which I have to copy the data from one table to another. The problem is that whenever I tried to perform the action of copying the data through this method, although the data gets copied, it performs reiterative copying that causes my program and my server to crash. 


  Here is the code snippet:

  #Empty Temporary Array
  $tmpHolder = array();
  $tmpHolder2 = array();
 
  #Loop through parts list

  foreach ($stringChunk1 As $part) {

#Create a single statement and stuff it in your tmp array
$tmpHolder[]=incidence.name LIKE '%{$part}';  
  }

  foreach ($stringChunk2 As $part2) {

#Create a single statement and stuff it in your tmp array
$tmpHolder2[]=regions.name LIKE '%{$part2}';  
  }


  #Join all the parts together, placing an OR between each element
  $string3= join(' OR ', $tmpHolder);
  $string2= join(' OR ', $tmpHolder2);
  $total=$count_chunk1 * $count_chunk2;

 //Entry a New Query Entry into scenarios table
   $query3=INSERT INTO scenarios VALUES('$scenario_name');
   $result3=mssql_query($query3) or die (The query has failed);
  
   #Search for the Regions and Incidence ID  
   $query_both=SELECT incidence.ID,regions.ID from incidence,regions WHERE ($string3)AND ($string2); 
   $result_both=mssql_query($query_both) or die (The query has failed);  


  while($row_both = mssql_fetch_array($result_both)) {

   $incidence_id= $row_both[0];
   $region_id= $row_both[1];

 //Enter entry into scenario elements table
//  $query14=INSERT INTO 
scenario_elements(region_id,incidence_id,market,number_sales,number_defer,customer_satisfaction)
//  SELECT 
region_id,incidence_id,market,number_sales,number_defer,customer_satisfaction FROM 
scenario_elements_2,regions,incidence WHERE $string2 AND $string3;
//  $result14=mssql_query($query14) or die (The query has failed);
  

I have to comment out the code snippet above because it creates something like 3 entries to the database. Could anyone please tell me if this is the error I have from my PHP, or is it from my SQL statement? How would I go about fixing this issue? 


An insert into select doesn't need to use a loop, you can use just one 
query:


insert into scenarios(field1, field2) select field1, field2 from 
other_table where 


the db will (internally) loop over the results and do the work.

--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php