mr cracker Posted May 27, 2010 Share Posted May 27, 2010 Hello, i need help with this please. I have this table in my DB I want to store the concepto column´s values in 2 php variables so i'll end up with this: $tax1=IEPS; $tax2=IVA; i'm using this query but its not working: $result = mysql_query("SELECT concepto FROM tbl_nimpuestos WHERE numventa = '$z' "); $row = mysql_fetch_array($result) $tax1 = $row[0]; $tax2 = $row[1]; $z is equal to 28 so i know that's not the problem. THANKS! Link to comment https://forums.phpfreaks.com/topic/203138-fetch-array-values/ Share on other sites More sharing options...
Alex Posted May 27, 2010 Share Posted May 27, 2010 Try this: $result = mysql_query("SELECT concepto, numventa FROM tbl_nimpuestos WHERE numventa = '$z' "); $row = mysql_fetch_assoc($result) $tax1 = $row['concepto']; $tax2 = $row['numventa']; Link to comment https://forums.phpfreaks.com/topic/203138-fetch-array-values/#findComment-1064360 Share on other sites More sharing options...
mr cracker Posted May 27, 2010 Author Share Posted May 27, 2010 Thanks for your reply. Using the above code i get this error: Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\.... on line 370 $tax1 = $row['concepto']; <------ This is Line 370 Link to comment https://forums.phpfreaks.com/topic/203138-fetch-array-values/#findComment-1064365 Share on other sites More sharing options...
kenrbnsn Posted May 27, 2010 Share Posted May 27, 2010 You need to loop through the returned set of rows: <?php $tax = array(); $q = "SELECT concepto, numventa FROM tbl_nimpuestos WHERE numventa = '$z' "; $result = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); while ($row = mysql_fetch_assoc($result)) { $tax[] = $row['concepto']; } echo '<pre>' . print_r($tax) . '</pre>'; // shows what's in the array ?> Ken Link to comment https://forums.phpfreaks.com/topic/203138-fetch-array-values/#findComment-1064366 Share on other sites More sharing options...
mr cracker Posted May 27, 2010 Author Share Posted May 27, 2010 Thankyou both, i had been there stuck for hours now Thank you. Link to comment https://forums.phpfreaks.com/topic/203138-fetch-array-values/#findComment-1064368 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.