473,385 Members | 1,397 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.

How do I get My SELECT query to select the information for the 3 ticked Items I chose

I have a list of tickboxes named "model" with different values genreated from mysql DB. When I tick 3 of them the script below below only bring the information of the last model ticked. how do I get the 3 ticked items to display at once. You urgent help is much appreciated.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $self = $_SERVER['PHP_SELF'];
  3. $Model = $_POST['Model'];
  4. if ( $Model );
  5. {
  6. $conn= mysql_connect('localhost,'user','cpass') or die( "could not CONNECT scotty" );
  7. $rs = mysql_select_db( "db name", $conn ) or die ( "no database" ); 
  8. $sql= "SELECT * FROM handsets WHERE Model = '$Model'";
  9. $rs= mysql_query( $sql, $conn ) or die( "could not do SELECT" );
  10.  
  11. while ( $row = mysql_fetch_assoc( $rs ))
  12. {  
  13. ?>
Jul 4 '10 #1
3 1417
TheServant
1,168 Expert 1GB
I think there is some HTML misunderstanding as well.
Have you made the name of your checkboxes an array?
Expand|Select|Wrap|Line Numbers
  1. <INPUT type="checkbox" name="test[]" value="Option1">Option 1<br /> 
  2. <INPUT type="checkbox" name="test[]" value="Option2">Option 2<br /> 
  3. <INPUT type="checkbox" name="test[]" value="Option3">Option 3<br />
And then you can look through that array to find what is checked. Not sure if this is your problem, but that will only give you the last value checked if you simply give the checkboxes the same name.
Jul 5 '10 #2
@TheServant
Hi Servant
Thanks for getting back to me.
I am new at PHP, so i think that my query that all the required data from my SQL database to form a series of tick boxes is the "array" see code below (that form the series of checkboxes based on how many models I have in the database). Thanks again for all the input you help is much appreiated.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $conn = mysql_connect('localhost,'root','password') or die("Could not do it");
  3. $rs = mysql_select_db("cosmonet") or die("wheres the DB");
  4. $sql ="SELECT Model, Image FROM handsets WHERE Brand = 'Brand_name'";
  5. $result = mysql_query($sql);
  6.  
  7. while( $row=mysql_fetch_array($result))
  8. $Model = $row['Model'];
  9. $image = $row['Image'];
  10. echo "<img src=\"http://bytes.com/images/$image\" width='50px' height='100%' align='absmiddle'><input name='$Model' type='checkbox' value='$Model' />$Model<br>";
  11. }
  12. ?>
Jul 8 '10 #3
TheServant
1,168 Expert 1GB
If you make the name a variable like $Model, then you will need to process each $Model checkbox separately. If you want it to be similar to your original post, then change the name to an array like:
Expand|Select|Wrap|Line Numbers
  1. while( $row=mysql_fetch_array($result))
  2. $Model = $row['Model'];
  3. $image = $row['Image'];
  4. echo "<img src=\"images/$image\" width='50px' height='100%' align='absmiddle'><input name='model[]' type='checkbox' value='$Model' />$Model<br>";
  5. }
The array $_POST['model'] will have all the models that were checked in it. Then you can process each with a foreach loop.
Jul 8 '10 #4

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

Similar topics

4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
0
by: Bill Agee | last post by:
I have a Select query which contains a field called AMWnum (long) which represents a sequence # of sorts. If I want to copy a row of information and paste it on the bottom, all is OK. I have...
1
by: Razia | last post by:
Hello everyone I want to create a select query according to the values in a single dimension array Select * from <table Name> where <Array items> Can anybody give me some suggestions
3
by: Sam Durai | last post by:
Here is a small testcase of the problem which I'm facing in prod env. db2 =describe table tab1 Column Type Type name schema name ...
1
by: Phil | last post by:
Is it possible to swap rows and columns in select query output so that each record's data is displayed in a column? I want to collect data each day and display it in a query with each day's date...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
2
by: sheenaa | last post by:
Hi, I want to display the last recorded record in the database of SQL SERVER 2005. How can i display it with the select query in the grid view... The database contains the...
2
by: runway27 | last post by:
hi i have an enquiry table which collects information about users making an online travel enquiry the fields in the table are = StoryTitle, EndCity, mode, PricedFrom, numAdults, numChildren,...
2
by: paulmitchell507 | last post by:
I think I am attempting a simple procedure but I just can't figure out the correct syntax. My asp (classic) page runs a SELECT query to obtain dates and ID's from 2 tables uSQL = "SELECT...
4
gregerly
by: gregerly | last post by:
Hello, I'm not sure how to properly format a query that I need to select some database information. I have two tables, one named "appts" and another "clients". They are linked by client_id. I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.