Jump to content

bazianm

New Members
  • Posts

    6
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

bazianm's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a simple foreach loop. The array has four rows in it. Really simple. I have confirmed the data in the array with var_dump. For some reason I cannot fathom, the loop is only processing rows 0 and 2 and is not processing 1 and 3. Here's the code snippet: <?php foreach ($postCals as $key=>$cal){ var_dump($postCals, $cal, $key); echo '<td style="text-align:right;>' . $cal . "</td>"; } ?> $postCals has precisely 4 values. Here's the output from this part of the code (in terms of the var_dumps). array (size=4) 0 => string '2.00000' (length=7) 1 => string '2.00000' (length=7) 2 => string '3.20000' (length=7) 3 => string '4.00000' (length=7) string '2.00000' (length=7) int 0 array (size=4) 0 => string '2.00000' (length=7) 1 => string '2.00000' (length=7) 2 => string '3.20000' (length=7) 3 => string '4.00000' (length=7) string '3.20000' (length=7) int 2 That's it. I two other foreach loops identical to this and they run fine! Any ideas? (misc info: php: 5.4.7 running on XAMPP/Windows )
  2. The simple query was just an example. The point of putting the queries into a database saves me from duplicating code. In effect, I am using data driven application development. I could have pages that join multiple tables and have multiple filters in the where clause...
  3. Well, here's the idea. I am creating a shell controller and view (I am using CodeIgniter). I can write one view and one controller that can control many different master tables for data entry. The differences between the various tables can be stored in a table. So, if I want to run the "customers" page, I can query the database to get all the information I need to run the customers page. Among the things that are different from table to table is the SQL select I will have to run the retrieve data for the page. So, one of the columns in the "pages" table is the SQL Select I will run in order to retrieve a specific customer record. By data driving the specific page information, I can save a lot of time in development. So, I will have a field called cRowSQL and it could have, as a string, the following SQL Select: SELECT customer.id, customer.name, customer.address, customer.city, customer.state, customer.zip, SUM(invoices.totalamount) as sales FROM customer LEFT OUTER JOIN invoice ON invoice.idcustomer = customer.id WHERE customer.id = '$id' I want to retrieve the SQL select and replace in the $id with the real value so I can get the row I want. If I were writing the code directly, I would encase the string in a double quote and it would evaluate the variable immediately. I want the same functionality except I am not storing it as a liternal string into SQL code variable. I am trying to figure out how to do that... Does this help?
  4. Hi, I would like to store sql query strings in a database. A query might look this like: SELECT * from ListTable where id = '$id' The idea would be to retrieve the string and run it as a SQL string. $id would be defined in the procedure so the idea is that when I send the SQL String through, $id would be replaced with its value and everything would work. Under normal circumstances, the code would look like this: $id = "somevalue"; $lcSQL = "SELECT * from ListTable where id = '$id'"; I would pass the SQL select off to mySQL and all is right with the world. I just want to store the string in a database, retreieve it and use it. Thanks for your help in advance...
  5. I figured it out. In this case, the array needed to use square brackets. It's funny, I had another case where I had to change it to regular parens... Not sure why but it seems to work now in my little test program. Thanks anyway!
  6. Hi, I am kind of new to php (although an experienced programmer in other languages). I am working on an application and I have a problem which I have been unable to figure out. I have googled it and still cannot get a handle on it. I have boiled it down to a simple example. Here's the code: <?php $array = gettest(); foreach ($array as $item) { if(gettype($item) == 'NULL') echo '<H1>WOW! A NULL!</H1>'; echo gettype($item).'<br>'; } function gettest(){ $lcFilter = "1|2|3"; $laFilter = explode('|',$lcFilter); if(!empty(laFilter(0))) laReturn('jobid') = laFilter(0); if(!empty(laFilter(1))) laReturn('stateid') = laFilter(1); if(!empty(laFilter(2))) laReturn('storeid') = laFilter(2); return $laReturn; } ?> When I run this, the line: if(!empty(laFilter(0))) laReturn('jobid') = laFilter(0); generates the error: I cannot think of what is wrong with the code. It seems simple enough. Any assistance would be greatly appreciated. Thanks
×
×
  • 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.