avraamG13 Posted May 4, 2009 Share Posted May 4, 2009 Hello, I'm having a code that shows in a list checkbox and next the row name i have on my database I want to select a checkbox and when i press display to show me tha information of the specific category if checked with my checkbox Here is my code: <table style="width: 100%"> <tr> <td colspan="3" class="titlebarmain"><strong>Select & View</strong></td> </tr> <tr> <td class="titlebarmainwhiter" style="height: 22px;">Selections</td> <td class="titlebarmainwhiter" style="width: 203px; height: 22px;"> </td> <td class="titlebarmainwhiter"> </td> </tr> <tr> <td> <td style="width: 185px"> <?php $result = mysql_query("SELECT * FROM players_category ORDER BY sort_order ASC"); while($row = mysql_fetch_array($result)) { $name = @$row["name"]; $cid = @$row["id"]; echo "<tr>"; echo "<td><input type=\"checkbox\" name=\"$name\" value=\"$cid\"> $name</td>"; // echo "<td class='selOverview'>" . $row['name'] . "</td>"; echo "</tr>"; } ?> </td> <td style="width: 203px"></td> <td> </td> </tr> <tr> <td colspan="3"> <input type="submit" name="display_player_cat" value="Display" class='button' ></td> </tr> </table> <br> Thank you Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/ Share on other sites More sharing options...
sKunKbad Posted May 4, 2009 Share Posted May 4, 2009 You need a form action and method, then you use the data that is sent by the form. If you choose to post, your form data will be available via the $_POST array. You can then use this form data as desired. Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/#findComment-825744 Share on other sites More sharing options...
avraamG13 Posted May 4, 2009 Author Share Posted May 4, 2009 is there any chance that you show me code exaomples becuse im new to php (noob) and i need examples to understant more please? Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/#findComment-825748 Share on other sites More sharing options...
sKunKbad Posted May 5, 2009 Share Posted May 5, 2009 http://w3schools.com/php/php_post.asp Sorry it took so long to respond. Here is a good explanation of what you need to know to make what you are doing happen. http://w3schools.com/php/php_post.asp Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/#findComment-826501 Share on other sites More sharing options...
erdomester Posted May 5, 2009 Share Posted May 5, 2009 I am a beginner in php, but this should help you, however my code is different. You missed everything that is needed to build up a connection between your program and the database. Unfortunately I was not be able to make the program handle multiselect. <html> <body> <?php session_start(); $conn=odbc_connect('DatabaseName','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM players_category ORDER BY NAME"; $result=odbc_exec($conn,$sql); if (!$result) {exit("Error in SQL");} $num=0; $_SESSION['n']=0; while (odbc_fetch_row($result)) { $name=odbc_result($result,"NAME"); $cid=odbc_result($result,"ID"); $array[$num][0]=$name; $array[$num][1]=$cid; $_SESSION['array'][$num][0]=$name; $_SESSION['array'][$num][1]=$cid; $num++; $_SESSION['n']++; } echo "<br>"; ?> <form name="names" method="post" action="<?php echo 'admin_sth'?>.php"> <?php for ($i=0; $i<$_SESSION['n']; $i++) { echo "<input type='checkbox' name='names' value=$i>".$_SESSION['array'][$i][0]; echo "<br>"; } ?> <input type="submit" value="Display"> </form> <?php odbc_close($conn); ?> </body> </html> admin_sth.php <?php session_start(); if ( isset($_POST['names']) ) { $names=$_POST['names']; for ($i=0; $i<13; $i++) { if ($names==$i) { $info=$_SESSION['array'][$i][0]; break; } } echo $info."'s id is ".$_SESSION['array'][$i][1]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/#findComment-826618 Share on other sites More sharing options...
avraamG13 Posted May 6, 2009 Author Share Posted May 6, 2009 Hey and thanks for your help, ive try the code but im getting the error: Fatal error: Call to undefined function odbc_connect() in .......................# Ive google it but i cant find a solution (OLD) Edited: Taking a closer look and ive found that this must be enable from your hosting provider, my provider cant offer this for share hosting so.. im unlucky .. Is there any other way or just give it up? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/#findComment-827107 Share on other sites More sharing options...
erdomester Posted May 6, 2009 Share Posted May 6, 2009 Because it the connection between access and php should be built manually, too. Follow these steps: 1.Open the Administrative Tools icon in your Control Panel. 2.Double-click on the Data Sources (ODBC) icon inside. 3.Choose the System DSN tab. 4.Click on Add in the System DSN tab. 5.Select the Microsoft Access Driver. Click Finish. 6.In the next screen, click Select to locate the database. 7.Give the database a Data Source Name (DSN). Click OK. It should work now. If you use other dbs just follow these steps again. Quote Link to comment https://forums.phpfreaks.com/topic/156792-checkbox-how-to-select-and-siplay-info-from-db/#findComment-827345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.