Tuesday, 15 January 2013

php - multiple arrays value fetching with session -



php - multiple arrays value fetching with session -

insert fine if select value database values fine single values fetch array problem don't know how solve task. please update code asap.

this insert code .....

<?php if(isset($_post['sendmessage'])){ $entermessage = $_post['teachermessage']; $checkbox_user = $_post['usernameallcheckbx']; $arr = implode(',',$checkbox_user); //$arr2 = explode(',',$arr); $insert = mysql_query("insert usermessages(fromteacher,toparent,messages) values('".$_session['username']."','$arr','$entermessage')"); if($insert == 1){ echo "<h1>successful</h1>"; } else{ echo mysql_error(); } } ?> <form method="post"> <div style="float:left; width:450px;"><br/><br/>message: <br/> <textarea style="width:400px; height:300px;" name="teachermessage"></textarea><br/> <input type="submit" value="send" name="sendmessage" /></div> <div style="float:left; with:200px; padding-top:55px;"> <table> <tr> <?php $select_query1 = mysql_query("select * register_user teacher='$teachername'"); while($chckbx=mysql_fetch_array($select_query1)) { ?> <td><?php echo "<input type='checkbox' name='usernameallcheckbx[]' value=". $chckbx['userid']." />"; ?></td> </tr> <tr> <td><?php echo $chckbx['parent_fname']." ".$chckbx['parent_lname']; ?></td> </tr> <?php } ?> </table> </div> </form>

and select code....

<h2>messages</h2> <?php $select_query3 = mysql_query("select * usermessages"); $fetch= mysql_fetch_array($select_query3); $data=$fetch['toparent']; $arr=explode(',',$data); //$userids=explode(',',$data); $sessionshow=$_session['userid']; $userids=in_array("$sessionshow",$arr); $select_query2 = mysql_query("select * usermessages toparent in ('$userids')='".$_session['userid']."'"); ?> <table border="0" cellpadding="0" cellspacing="0"> <tr> <th>teacher name</th> <th>message</th> </tr> <?php while($fetch_name2=mysql_fetch_array($select_query2)) { echo "<tr>"; echo "<td>".$fetch_data=$fetch_name2['fromteacher']."</td>"; echo "<td>".$fetch_data=$fetch_name2['messages']."</td>"; echo "</tr>"; } ?> </table>

i have set reply show wrong code - remove fetch info loop doesn't anything

while($fetch_name2=mysql_fetch_array($select_query2)) { echo "<tr>"; echo "<td>".$fetch_name2['fromteacher']."</td>"; echo "<td>".$fetch_name2['messages']."</td>"; echo "</tr>"; }

even improve utilize of heredoc:

while($fetch_name2=mysql_fetch_array($select_query2)) { echo <<<eof <tr> <td>{$fetch_name2['fromteacher']}</td> <td>{$fetch_name2['messages']}</td> </tr> eof; }

php mysql database

No comments:

Post a Comment