Search the Community
Showing results for tags 'extract()'.
-
I have the following general mySQL query: $query = sprintf( "SELECT a.A, a.B, ..., a.C, FROM a WHERE a.A = %s ORDER by a.A;", implode(" OR a.A = ", $_SESSION['values'])); for some records, B has a value, and for others, B is NULL. That is what I want. I extract the query with the following PHP: for ($i = 0; $i < $nrows; $i++){ $row = mysqli_fetch_assoc($result);//fetches data stored within each row extract($row); echo "<tr>"; foreach($row as $column => $field){ if($field == $...){ ... } elseif($field == $C){ echo"<td> <input type='text' name='C+[]' value='$C'> </td>"; } echo "</tr>" } In the resulting html table, records containing not null B fields are presented accurately, while records with null B fields incur a duplication of field C. This offset occurs at the beginning of the record, pushing the final field in the record outside the table boundaries. I think I've narrowed down the problem to the extract() function, as r_print readouts of every other variable in the script returns the accurate field names and values. But, running print_r on $row after extract() provides an identical printout to other variables in the script. What are some possible ways I can stop the duplication of field C from occurring? Happy to provide more information upon request.
-
if i use code as follows, This is a safe way to take the value of the form ? <html> <head></head> <body> <form method='post'> <input type='text' name='name' value='akli'> <input type='submit' name ='view' value='view'> </form> </body> </html> <?php extract($_POST); if($view) echo $name; ?> please healp me
-
Hey guys, I am trying to grab and loop data from my DB with a while loop and extract() function. right now i have something like this: echo '<div>'; // CONTAINER DIV echo '<h2>News about '. $db_name. '</h2>'; $query = 'SELECT * FROM `news_to_people` WHERE `people_db_id` = '.$db_id; $r_query = mysql_query($query); while($rows=mysql_fetch_assoc($r_query)){ extract($rows); $new_q = 'SELECT * FROM `news` WHERE `id` = '.$news_id; $run_q = mysql_query($new_q); $rows = mysql_fetch_assoc($run_q); extract($rows); echo '<ul>'; echo '<l1><a href="article?articleid='.$id.'&name='.$db_name.'">'.$title.'<br></l1>'; echo '</ul>'; } echo '</div>'; // END TO CONTAINER Now here i get the loop to fire correctly and execute. It then loops all 170+ links except in the middle of the loop , there is an error: so this means that i have a failed 2nd query somewhere in that it is skipping inside the while loop. i need to debug and find which query is bringing this error. my question is what is the best way i can write an if statement to see which query is failing or which query is not returning a proper array. also my if the query was failing wouldn't the error be asking for a proper resource ? this means the query is firing correctly and the extract() function is failing to receive all the rows. meaning that one of the rows must be returning empty or zero ? any help is much appreciated.
- 3 replies
-
- while loop
- php
-
(and 3 more)
Tagged with: