Jump to content

[SOLVED] trying to input some GET data into a query


ballhogjoni

Recommended Posts

I have this code that places data into an input field as an array. IE <input type="hidden" name="id[{$info.id}]" /> The problem is extracting that data using php on the accepting page. Basically I want to loop through the array and extract the id for each input and place it into the query on the accepting page.

 

This is line of code I am having issues with(found in second code snippet):

foreach($queryId as $k=>$qid) {

$sql .= $k;

}

 

 

smarty html form

<form action="" method="GET">
  <table cellpadding="5" cellspacing="5" border="1" style="padding-left:15px;">
   <tr>
    <td colspan="2">Viewing All {$categoryType} For The {$categoryName} Category</td>
   </tr>
   <tr>
    <td>{$categoryType} Name</td>
    <td>Order</td>
   </tr>
   {foreach from=$allInfo item=info}
   <tr bgcolor="{cycle values="white,"}">
     <td style="font-size:12px"><a href="{$base_href}intranet/{$lowerCategoryType}">{$info.name}</a></td>
     <!--<td><a style="font-size:12px" href="{$base_href}intranet/categories/edit.html?id={$info.category_id}">Edit</a> <a style="font-size:12px" href="javascript:confirmation('{$base_href}intranet/categories/delete.html?id={$info.category_id}')">Delete</a></td>-->
     <td align="center">
     <input type="text" size="2" name="order[{$info.category_id}][]" value="{$info.weight}" />
     <input type="hidden" name="table" value="{$table}" />
     <input type="hidden" name="type" value="{$type}" />
     <input type="hidden" name="id[{$info.id}]" />
     </td>
    </tr>
   {/foreach}
   <tr>
    <td colspan="3" align="center"><input type="submit" value="Change Order" /></td>
   </tr>
  </table>
  </form>

 

Accepting page code

<?php
if ($_GET['order']) {
$order = $_GET['order'];
$queryId = $_GET['id'];
foreach($order as $id=>$misc) {
 $cat_id = $id;
	  foreach($misc as $weight) {
	   $sql = "UPDATE ".$_GET['table']." 
	   			SET weight = '".$weight."' 
				  WHERE category_id='".$cat_id."' AND ".$_GET['type']."_id = ";
		foreach($queryId as $k=>$qid) {
		 $sql .= $k;
		}
	   $res = $this->db->query($sql);
	    if(!$res){
		 $results =  "there is a problem with your query. Error: ".mysql_error()."<br>\n";
		} else {
		 $results = "Query $sql was run successfully<br>\n";
		}
		echo $results;
	  }
	 }
	 exit;
	 header("Location: ".$GLOBALS['site_variables']['base_href']."intranet/categories?categoryUpdate=1");	
	} else {
	 $this->set('table',$_GET['table']);
	 $this->set('type',$_GET['type']);
	 $query = $this->db->getAll("
	 SELECT ".$_GET['table'].".category_id,".$_GET['table'].".weight,".$_GET['tableTwo'].".name,".$_GET['tableTwo'].".".$_GET['type']."_id AS id
	 	FROM ".$_GET['table'].",".$_GET['tableTwo']." 
			WHERE ".$_GET['table'].".".$_GET['type']."_id = ".$_GET['tableTwo'].".".$_GET['type']."_id 
				AND ".$_GET['table'].".category_id = '".$_GET['id']."'
					ORDER BY ".$_GET['tableTwo'].".name ASC");
			//print_r($query);exit;
	 $this->set('allInfo', $query);
         $this->set('viewAll', true);
	}
      }
?>

I figured it out. ;D

 

I had to add the {$info.id} to the first array. so it ended up looking like this:

<input type="text" size="2" name="order[{$info.category_id}][{$info.id}]" value="{$info.weight}" />

 

From there I could parse the info with 2 foreach loops.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.