•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 391,991 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,253 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 1010 | Replies: 9 | Solved
![]() |
Do you want a single query where the values in your array are in the where ? Like this:
$values = implode(",", $your_array);
$query = "SELECT * FROM table WHERE column IN ($values)"•
•
Join Date: Jun 2008
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
Hi
Thanks for that. From what I understand this may well be the solution. The only problem is deploying it.
So far I'm trying ...
... but its not working. Can you tell me if I am on the right track here please?
Thanks for that. From what I understand this may well be the solution. The only problem is deploying it.
So far I'm trying ...
php Syntax (Toggle Plain Text)
<?php $Prescriber_Name = $_POST[thing]; $values = implode(", ", $Prescriber_Name); // open the connection $conn = mysql_connect("location", "username", "password"); // pick the database to use mysql_select_db("database",$conn); //create the sql statement $query = "SELECT * FROM prescribing_test WHERE prescribing_test.Prescriber_Name IN ($values)" //execute the SQL statement $result = mysql_query($query, $conn) or die(mysql_error()); mysql_close($conn); ?> <table> <tr> <th><B>Prescriber Name</B></th> <th><B>BNF Name</B></th> <th><B>Total Items</B></th> </tr> <? //go through each row in the result set and display data while($newArray = mysql_fetch_array($result)) { ?> <tr> <td><?=$newArray["Prescriber_Name"]?></td> <td><?=$newArray["BNF_Name"]?></td> <td>><?=number_format($newArray["Total_Items"],0,'.',',')?></td> </tr> <? } ?> </table>
... but its not working. Can you tell me if I am on the right track here please?
Last edited by peter_budo : Jun 14th, 2008 at 1:39 pm. Reason: Code tag correction, closing tag is [/code] not [\code]
Can you tell me what's not working ?
If nothing is displayed, perhaps because you need to
I don't know if your site is setup to use <?= as a short tag for echo.
If nothing is displayed, perhaps because you need to
<?php echo $newArray["BNF_Name"]; ?>
I don't know if your site is setup to use <?= as a short tag for echo.
"Premature optimization is the root of all evil."
Donald Knuth / Tony Hoare
Donald Knuth / Tony Hoare
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 1
Looks like you need to put single quotes around $value in setting the $query variable, such as follows:
SQL Tutorial
$query = "SELECT * FROM prescribing_test WHERE prescribing_test.Prescriber_Name IN ('$values')";SQL Tutorial
•
•
Join Date: Jun 2008
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
Thanks again for taking the time to help me with this.
As it stands, the code I posted doesn't display anything ( all I get is a blank page, no graphics and no text).
When I add single quotes and a semi colon to the query as suggested
I get my graphics, text and table headings but unfortunately no output from the query. I've tried
but it didn't change anything.
I have added a row count to the code
and this shows zero rows. Does this suggest that I'm not getting the data into the query in the first place?
As it stands, the code I posted doesn't display anything ( all I get is a blank page, no graphics and no text).
When I add single quotes and a semi colon to the query as suggested
php Syntax (Toggle Plain Text)
$sql = "SELECT * FROM prescribing_test WHERE Prescriber_Name IN ('$value')";
I get my graphics, text and table headings but unfortunately no output from the query. I've tried
php Syntax (Toggle Plain Text)
<?php echo $newArray["BNF_Name"]; ?> <?php echo $newArray["BNF_Name"]; ?>
but it didn't change anything.
I have added a row count to the code
php Syntax (Toggle Plain Text)
$num_rows = mysql_num_rows($result); echo "$num_rows Rows";
and this shows zero rows. Does this suggest that I'm not getting the data into the query in the first place?
Last edited by peter_budo : Jun 14th, 2008 at 1:40 pm. Reason: Code tag correction, closing tag is [/code] not [\code]
•
•
Join Date: Jun 2008
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
I've found the problem!
Adding single quotes to the comma in the implode statement now gives me the expected results.
Not sure yet why this is needed but hey it works.
Thanks guys!
Adding single quotes to the comma in the implode statement now gives me the expected results.
php Syntax (Toggle Plain Text)
$values = implode("','", $_POST[thing]);
Not sure yet why this is needed but hey it works.
Thanks guys!
Last edited by peter_budo : Jun 14th, 2008 at 1:41 pm. Reason: Code tag correction, closing tag is [/code] not [\code]
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb MySQL Marketplace
Other Threads in the MySQL Forum
- Previous Thread: urgent--Dynamically populating local database
- Next Thread: get entries other than the related ones


Linear Mode