Jump to content

Recommended Posts

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

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];
}

?>

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.