what is wrong

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

what is wrong

Post by jeremybass »

hello, quick question... what is wrong with this....?

Code: Select all

if ($types_picked['extra_fields_type_cat_id'] == '999999999') {                                    
        $picked = 'true';
      } else {
        $picked = 'false';
      }
thank and have a great day
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: what is wrong

Post by John Cartwright »

Depends, what are you trying to do?
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

hello, um..... if 'extra_fields_type_cat_id' = '999999999' then $picked = 'true' } else { $picked = 'false'

i just what $picked to = true or faluse from 'extra_fields_type_cat_id'
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: what is wrong

Post by JAM »

replace the if-clause with

Code: Select all

echo $types_picked['extra_fields_type_cat_id']
...and see what it says.
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

damn nothing... it's located in a loop and is supost to check a checkbox feild if the extra_fields_type_cat_id=9999999 (meaning it is there or not only) then on refresh ....on and on...

here is the code for that area... may some will have an idea...

Code: Select all

<?php  
       echo tep_draw_form('extra_fields', FILENAME_SUPERFIELDSTYPE, 'action=update' . '&' . 'cPath=' . $cPath . '&pID=' . $pInfo->products_id,'post');
      ?>
<?php
$extra_fields_query_update = tep_db_query("SELECT * FROM " . TABLE_EXTRA_FIELDS_TYPE . " WHERE extra_fields_type_status=1 ORDER BY extra_fields_type_order");
$types_picked_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and extra_fields_type_id='" .tep_db_input($key) . "'");
$types_picked = tep_db_fetch_array($types_picked_query);
while ($extra_fields = tep_db_fetch_array($extra_fields_query_update)) {
 
 
?>                        
<?php echo ($types_picked['extra_fields_type_cat_id'] == '999999999') {                                    
        $picked = 'true';
      } else {
        $picked = 'false';
      }; 
echo tep_draw_checkbox_field('mark['.$extra_fields['extra_fields_type_id'].']', $pInfo->products_id, $picked); ?>
<?php echo $extra_fields['extra_fields_type_name']; ?> &nbsp;&nbsp; 
 
<br/>
  <?php } ?> <?php echo tep_image_submit('button_update_fields.png',IMAGE_UPDATE_FIELDS); ?>
i hope the more eyes on it the better... thanks all for the fast reply... i think i'll have to stop in more often
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: what is wrong

Post by John Cartwright »

What does

Code: Select all

 
echo '<pre>';
print_r($types_picked);
echo '</pre>';
yield?
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

:( nothing...
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

ok... you guys can't tell i'm new to php... only 4 months now.... now could the problem lay in my query sntax or placement?
Last edited by John Cartwright on Sun Jan 20, 2008 11:34 am, edited 1 time in total.
Reason: Please do not bump your thread within 24 hours of your last post. Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: what is wrong

Post by John Cartwright »

Code: Select all

$types_picked_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and extra_fields_type_id='" .tep_db_input($key) . "'");
your tep_db_query() is not returning any rows from the query. I'm not sure if you are expecting there to be a row(s) returned or not :S

A couple things we can move forward with.. try inserting this into your code. Take whatever is returned and try running the query in phpmyadmin to see if any rows are returned.

Code: Select all

echo "SELECT * FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and extra_fields_type_id='" .tep_db_input($key) . "'";
If you are getting some rows returned, then there is a problem with your tep_db_query() perhaps. Try posting that code as well please.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: what is wrong

Post by John Cartwright »

Try replacing all instances of $HTTP_GET_VARS with $_GET also.

$HTTP_GET_VARS is deprecated.
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

ok so i tryed it and found the error in the query

Code: Select all

<?php  
       echo tep_draw_form('extra_fields', FILENAME_SUPERFIELDSTYPE, 'action=update' . '&' . 'cPath=' . $cPath . '&pID=' . $pInfo->products_id,'post');
      ?>
<?php
$extra_fields_query_update = tep_db_query("SELECT * FROM " . TABLE_EXTRA_FIELDS_TYPE . " WHERE extra_fields_type_status=1 ORDER BY extra_fields_type_order");
$types_picked_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE products_id = '" . (int)$HTTP_GET_VARS['pID'] . "' and extra_fields_type_id='" . $extra_fields['extra_fields_type_id'] . "'");
$types_picked = tep_db_fetch_array($types_picked_query);
while ($extra_fields = tep_db_fetch_array($extra_fields_query_update)) {
 
 
?>                        
<?php if ($types_picked['extra_fields_type_cat_id'] == '999999999') {                                    
        $picked = 'true';
      } else {
        $picked = 'false';
      } 
echo tep_draw_checkbox_field('mark['.$extra_fields['extra_fields_type_id'].']', $pInfo->products_id, $picked); ?>
<?php echo $extra_fields['extra_fields_type_name']; ?> &nbsp;&nbsp; 
 
<br/>
  <?php } ?> <?php echo tep_image_submit('button_update_fields.png',IMAGE_UPDATE_FIELDS); ?> </form>
so those are the changes that make the out-put right but another proble poped up lol... always the case...

Code: Select all

      tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$HTTP_GET_VARS['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$HTTP_GET_VARS['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
 
is creating duplicated rows... but still the if lause is not working right....
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

Try replacing all instances of $HTTP_GET_VARS with $_GET also.

$HTTP_GET_VARS is deprecated.
well try
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

Code: Select all

    tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$HTTP_GET_VARS['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$HTTP_GET_VARS['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
never mind on that... forgot i turns the defult in phpMyAdmin was off... no luck with the if clase
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

ok $types_picked is returning an array set.... but the if is half working
output is
---------------------------------------------
is checked (suppost to be)

1
tArray
(
[products_id] => 75
[extra_fields_type_id] => 39
[extra_fields_type_cat_id] => 999999999
[extra_fields_type_cat_values_id] => 999999999
)
SELECT * FROM products_to_extra_fields WHERE products_id = '75' and extra_fields_type_id='39'Processor
------------------------------------------------
is checked (not suppost to be)

tSELECT * FROM products_to_extra_fields WHERE products_id = '75' and extra_fields_type_id='55'ffff

----------------------------------------------------

lastest code

Code: Select all

<?php  
       echo tep_draw_form('extra_fields', FILENAME_SUPERFIELDSTYPE, 'action=update' . '&' . 'cPath=' . $cPath . '&pID=' . $pInfo->products_id,'post');
      ?>
<?php
$extra_fields_query_update = tep_db_query("SELECT * FROM " . TABLE_EXTRA_FIELDS_TYPE . " WHERE extra_fields_type_status=1 ORDER BY extra_fields_type_order");
 
while ($extra_fields = tep_db_fetch_array($extra_fields_query_update)) {
$types_picked_query = tep_db_query("SELECT * FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE products_id = '" . (int)$_GET['pID'] . "' and extra_fields_type_id='" . $extra_fields['extra_fields_type_id'] . "'");
$types_picked = tep_db_fetch_array($types_picked_query);
echo ($types_picked['extra_fields_type_cat_id'] == 999999999);
if ($types_picked['extra_fields_type_cat_id'] == 999999999) {                                    
        $picked = 'true';
      } else {
        $picked = 'false';
      } 
      
 
?>                        
<?php 
      echo '<pre>t';
print_r($types_picked);
echo '</pre>';
echo "SELECT * FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE products_id = '" . (int)$_GET['pID'] . "' and extra_fields_type_id='" . $extra_fields['extra_fields_type_id'] . "'";
echo tep_draw_checkbox_field('mark['.$extra_fields['extra_fields_type_id'].']', $pInfo->products_id, $picked); ?>
<?php echo $extra_fields['extra_fields_type_name']; ?> &nbsp;&nbsp; 
 
<br/>
  <?php } ?> <?php echo tep_image_submit('button_update_fields.png',IMAGE_UPDATE_FIELDS); ?> </form>
jeremybass
Forum Commoner
Posts: 25
Joined: Sun Jan 20, 2008 10:52 am

Re: what is wrong

Post by jeremybass »

got it... it was the ' ' around the true false.... i'll have to remeber to debug like that... works great... thanks all..
Post Reply