473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Retrieve Array Data through List/Menu box using Mysql query

Hi ALL

I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box.
When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the entire data of the user corresponding to that category.
However when i check multiple checkboxes and in the category select all those checked values to find if any user fits in all those category and hence prompt the entire data corresponding to it,the column shows only 'array' and not array values. So please anyone guide me as how should i fetch all the checked categories through the list/menu box.
Here goes the edited code:


Code to insert the array values in mysql database using checkboxes
[PHP]
<?
$state=$_POST['state'];
$state = implode(",", $state);

$query="insert into consult (state)VALUES('$state')";
mysql_query($query);
?>
<form name="form" action="abc.php" method ="post">
<input name=state[0] type="checkbox" value="Air Conditioning Consultants & Contractors">Air Conditioning Consultants & Contractors
<input name=state[1] type="checkbox" value="Arbitrators" >Arbitrators
<input name=state[2] type="checkbox" value=Builders,Contractors & Developers>Builders,Contractors & Developers
<input name=state[3] type="checkbox" value=Civil Engineers and Contactors>
Civil Engineers and Contactors
</form>
<input name="submit" type="submit" class="style40" value="Submit">

[/PHP]

Code to fetch those checked array values using list/menu box.
[PHP]
<?php
if (isset($_POST['submit']))

{
$state=$_POST['state'];
$state=explode(",",$state);
}
?>
<form name="form1" action="cons_show.php" method="post" >
<select name="state">
<option selected >Select</option>
<option value="Air Conditioning Consultants & Contractors">Air Conditioning Consultants & Contractors</option>
<option value="Arbitrators">Arbitrators</option>
<option value="Builders,Contractors & Developers">Builders,Contractors & Developers</option>
<option value="Civil Engineers and Contractors">Civil Engineers and Contractors</option>
</form>

if(!isset($cmd)) {

$state=$_POST['state'];

$query = @mysql_query("SELECT * FROM consult where state='$state'");

if (!$query)
{
exit('<p>Error retrieving entries from database!<br/>'.'Error: ' . mysql_error() . '</p>');
}

$sql = mysql_fetch_array($query);
if($sql){

echo '<table width="90%" cellspacing="2" cellpadding="4" border="1"><tr><td valign="top">

<table><tr><td ><h4 ><u> Customer Information</u> </h4></td></tr></table>';

echo '<table cellpadding="4"><tr><td ><b>Firm Name</b></td><td ><b>State</b></td><td><b>City</b></td>

<td><b>Contact</b></td><td><b>Email Address</b></td></tr>';

$firm = $sql['firmname'];

$address = $sql['adress'];

$city= $sql['city'];

$pin=$sql['pin'];

$tel=$sql['tel'];

$fax=$sql['fax'];

$email=$sql['email'];

$state=$sql['state'];

echo "<tr><td><a href='cons_details.php?cmd=edit&STATE=$state'>$fir m</a></td><td>$state</td><td>$city</td><td>$tel</td><td>$email</td>";

echo "<td>";
echo "</tr></table>";

}
else {
echo '<table ><tr><td>';


[/PHP]

This is how i have worked.but it is only useful for only a single checked data and cease to work on multiple checked data.
So if anyone ca help please do it.

Thanks and Regards
TechnoAtif
Feb 23 '08 #1
4 6473
ronverdonk
4,258 Expert 4TB
Where is variable '$cmd' set or assigned a value? Not knowing that makes it hard to follow your code. Statement
[php]$query="insert into consult (state)VALUES('$state')";[/php]
makes field state a string of states separated by comma's.

Somewhere in the 2nd piece of code you make $state an array. [php] $state=explode(",",$state);[/php]But you cannot compare a single value field state with an array $state.

So I suspect we have not seen al your code. Please show it and this time within the appropriate code tags!

Ronald
Feb 24 '08 #2
Hi

Here is the page where cmd value has been posted.Basically it shows the checked values from the chexkboxes...but does not shows the selected values from the select box as i navigate to this page through the link given in the previous page. Hopt this could help you to give me sm able solution

[PHP]<?php include "dbconnect.php";


if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$city = $_GET["CITY"];

$sql = "SELECT * FROM consult where state'$state' ";
$result = mysql_query($sql);
$query = mysql_fetch_array($result);

?> [/PHP]

[HTML]<form name="form" action="cons_details.php" >

<table width="86%">
<tr><td colspan="4" class="style38"><b>Status (Tick as many as applicable):</b></td>
</tr>
<tr><td><?php echo "$query[state]<br/>" ; ?></td>
</tr> </table>
</form>[/HTML]

Thanks and Regards
Mohammad Atif
Feb 25 '08 #3
ronverdonk
4,258 Expert 4TB
You still have not shown all code. E.g. the next piece of code is odd. Upon entry you get data from field 'state' in the $_POST array and 10 lines down you show a form asking for checkboxes that fille the 'state' array. This cannot work like you have shown it.[php]<?
$state=$_POST['state'];
$state = implode(",", $state);

$query="insert into consult (state)VALUES('$state')";
mysql_query($query);
?>
<form name="form" action="abc.php" method ="post">
<input name=state[0] type="checkbox" value="Air Conditioning Consultants & Contractors">Air Conditioning Consultants & Contractors
<input name=state[1] type="checkbox" value="Arbitrators" >Arbitrators
<input name=state[2] type="checkbox" value=Builders,Contractors & Developers>Builders,Contractors & Developers
<input name=state[3] type="checkbox" value=Civil Engineers and Contactors>
Civil Engineers and Contactors
</form>
<input name="submit" type="submit" class="style40" value="Submit">
[/php]I am sure there is a mixup of all those various pieces of code and it cannot be seen how they are working together. So show us all; the code if you want a sensible answer.

You have not replied to my remark about using the state array as a single value.

Ronald
Feb 25 '08 #4
Ok..Sorry..

Coding for the first two pages are same ,next i'm giving the coding for next two pages:

In this third page the data should be shown on the click of the submit buttton of

the previous page as written above:

Third page:
===========
[PHP]<?php

include "dbconnect.php";
//error_reporting('notice');

if(!isset($cmd)) {


$state=$_POST['state'];


$query = @mysql_query("SELECT * FROM consult where state='$state'");

if (!$query)
{
exit('<p>Error retrieving entries from database!<br/>'.'Error: ' . mysql_error() . '</p>');
}

$sql = mysql_fetch_array($query);

if($sql){

echo '<table width="90%" cellspacing="2" cellpadding="4" border="1"><tr><td valign="top">

<table><tr><td ><h4 ><u> Customer Information</u> </h4></td></tr></table>';

echo '<table cellpadding="4"><tr><td ><b>Firm Name</b></td><td ><b>Category</b></td><td><b>City</b></td>

<td><b>Contact</b></td><td><b>Email Address</b></td></tr>';


//while ($sql) {



$cid = $sql['cid'];

$firm = $sql['firmname'];

$address = $sql['adress'];

$city= $sql['city'];

$pin=$sql['pin'];

$tel=$sql['tel'];

$fax=$sql['fax'];

$email=$sql['email'];

$pass=$sql['pass'];

$state=$sql['state'];

$prj1=$sql['prj1'];

$prj2=$sql['prj2'];

$prj3=$sql['prj3'];

$cprj1=$sql['cprj1'];

$cprj2=$sql['cprj2'];

$cprj3=$sql['cprj3'];

$award=$sql['award'];

$keyperson=$sql['keperson'];

$des=$sql['design'];

$time=$sql['time'];

echo "<tr><td><a href='cons_details.php?cmd=edit&STATE=$state'>$fir m</a></td><td>$state</td><td>$city</td><td>$tel</td><td>$email</td>";

echo "<td>";



echo "</tr></table>";

}
else {
echo '<table ><tr><td>';

echo "<font class=font>

<pre>

The database corresponding to your choice of city is

currently unavailable.Please try after some time to

get the better results.

Thanks</font>

</pre>";

echo '</td></tr></table>';
}

}

?>[/PHP]

================================================== ====

This last page will show the data of a particular firm after clicking on the link below the firmname:



[PHP]<?php include "dbconnect.php";
error_reporting('notice');

if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$state = $_GET["state"];

$sql = "SELECT * FROM consult where state='$state' ";
$result = mysql_query($sql);
$query = mysql_fetch_array($result);
//redirect("protoshow.php");
//exit();
?> [/PHP]
[HTML]<form name="form" action="cons_details.php" method="post">
<h3><center class="style78">FOR ASSOCIATES/CONSULTANTS
</center></h3>
<table width="400" >
<!--<tr>
<td width="22%" class="style40">< ?php echo $query['cid'];?></td>
</tr>
-->
<tr>
<td width="45%" class="style38">
<b>Name of Firm:</b>
</td>
<td width="11%" class="style40"><?php echo $query['firmname'];?></td>
</tr>
<tr>
<td class="style38"><strong>Address</strong></td>
<td class="style40"><?php echo $query['adress'];?></td>
</tr>

<tr>
<td class="style38"><strong>City:</strong></td>
<td class="style40"><?php echo $query['city'];?></td>
<td width="27%" class="style38"><strong>Pin: </strong></td>
<td width="17%" class="style40"><?php echo $query['pin'];?></td>
</tr>
<tr>
<td class="style38"><strong>Tel:</strong></td>
<td class="style40"><?php echo $query['tel'];?></td>
<td class="style38"><strong>Fax: </strong></td>
<td class="style40"><?php echo $query['fax'];?></td>
</tr>
<tr><td class="style38"><strong>E-mail:</strong></td>
<td class="style40"><?php echo $query['email'];?></td>
</tr>
</table>
<table width="86%">
<tr><td colspan="4" class="style38"><b>Status (Tick as many as applicable):</b></td>
</tr>
<tr><td><?php echo "$query[state]<br/>" ; ?></td>
</tr> </table>

</form>[/HTML]
[PHP]<?php }} ?>[/PHP]

Hope this gives u some clue

Somewhere in the 2nd piece of code you make $state an array.
Code: ( php )
$state=explode(",",$state);
But you cannot compare a single value field state with an array $state.
I cannot get you...can u please elaborate
Feb 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Philip D Heady | last post by:
Ok, as some of you may know I'm an Oracle newbie w/ PHP. I'd rather use MySQL but at the office here we use Oracle and boy do I have alot to learn. I'm starting to hate it after using MySQL!! ...
4
by: JaNE | last post by:
I'm trying to get some data from MySql database and to create switch based on those data, but as an php beginer, I have no clear idea how to do this. have tryed many options which loked promising,...
0
by: Erik Summers | last post by:
I am new to php/mysql but not new to server side scripting in general. I have built an app using DreamWeaver MX, PHP and MySQL. It is working well but there is one final functionality I need and...
0
by: Donald Tyler | last post by:
Then the only way you can do it that I can think of is to write a PHP script to do basically what PHPMyAdmin is trying to do but without the LOCAL in there. However to do that you would need to...
16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
11
by: Jim S. | last post by:
hi guys and gals, i have an array, but i have the hardest time putting the value in the table, so what is the normal procedure? thanks Jim
3
mmarif4u
by: mmarif4u | last post by:
Hi everyone, I have a little problem in php coding. i have mysql table guestbook: Fields are Id,name,email,comment,datetime. Now i want to search the database by php query using a Dropdown menu...
12
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.