Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2006, 08:21 AM
Authorized User
 
Join Date: Oct 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset into array

Hi

I am trying to extract information from a database (on a relist an item page) and find out the last item listed allowed postage to one or more of the locations I have stored in the database.

I currently have had to extract all the information in 3 separate recordsets:
<sql>
SELECT postto.location_id
FROM postto
WHERE postto.listing_id=item AND postto.location_id=1

SELECT postto.location_id
FROM postto
WHERE postto.listing_id=item AND postto.location_id=2

SELECT postto.location_id
FROM postto
WHERE postto.listing_id=item AND postto.location_id=3
</sql>
as you see I have 1 of 3 possible values to find in the database, its 1-UK, 2-Europe, 3-Worldwide

But this seems very inefficient, so is there a way I can extact the information with one recordset and store it in an array (for example) and then see if 1, 2 or 3 of the values appear in the array?

Like this
<sql>
SELECT postto.location_id
FROM postto
WHERE postto.listing_id=item
</sql>
Then put content into an array and see if and of the checkboxes need to be checked for that postal location.

I currently put the values into a session variable so the user can dynamically change them on the relist page.

<input <?php if (!(strcmp("$_SESSION[uk]",1))) {echo "checked=\"checked\"";} ?> name="uk" type="checkbox" id="uk" value="1" />UK

<input <?php if (!(strcmp("$_SESSION[eu]",2))) {echo "checked=\"checked\"";} ?> name="eu" type="checkbox" id="eu" value="2" />
        Europe

 <input <?php if (!(strcmp("$_SESSION[ww]",3))) {echo "checked=\"checked\"";} ?> name="ww" type="checkbox" id="ww" value="3" />
        Worldwide

Is there a way I can extract all the information via one recordset and access the result to see if 1, 2 or 3 of the values appears?

This may be a simple question but I cannot seem to get my head around it.

Thanks
David
 
Old August 8th, 2006, 07:57 AM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If I'm correct your trying to get the records that have the id's 1,2,3 and are items.

If so try this querry
Code:
SELECT postto.location_id
FROM postto
WHERE postto.listing_id=item AND postto.location_id BETWEEN 1 AND 3
If this is not the data you want to retrieve from your database, can you tell what you want te retrieve.
__________________________________________________ ________
This is my junk I'm gona eat it
 
Old August 8th, 2006, 08:36 AM
Authorized User
 
Join Date: Oct 2003
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

The recordset can return any combination of 1, 2 and 3, thats why I was thinking of an array,
i.e.
/////example
<sql>
SELECT postto.location_id
FROM postto
WHERE postto.listing_id=1384</sql>

item number 1384 can return 1,2,3
1 alone
2 alone
3 alone
 or any combination of the 3, the only rules I have created for the recordset is that the user must select 1 of the 3 choices.
////// end example

So what I want to do is put whatever results the above query returns into an array to check the checkbox, with 1 query alone not 3 individual queries.

I am using Dreamweaver 8 to do this and it will allow you to dynamically check a checkbox if a value is present in a variable, (1, 2 or 3 in this case) but not if a value appears in an array, so I will have to manually create the array of results.

The Actual recordset created by Dreamweaver is this:

$item_alllocations = "-1";
if (isset($_SESSION['listingid'])) {
  $item_alllocations = (get_magic_quotes_gpc()) ? $_SESSION['listingid'] : addslashes($_SESSION['listingid']);
}
mysql_select_db($database_localhost, $localhost);
$query_alllocations = sprintf("SELECT postto.location_id FROM postto WHERE postto.listing_id=%s", GetSQLValueString($item_alllocations, "int"));
$alllocations = mysql_query($query_alllocations, $localhost) or die(mysql_error());
$row_alllocations = mysql_fetch_assoc($alllocations);
$totalRows_alllocations = mysql_num_rows($alllocations);


and then the repeat region is:

<?php do { ?>
          <?php echo $row_alllocations['location_id']; ?>
          <?php } while ($row_alllocations = mysql_fetch_assoc($alllocations)); ?>

This returns 1 2 3 which means that the listing will allow delivery to UK, Europe and Worldwide, but how do I check the checkboxes with the results from one query?

David





Similar Threads
Thread Thread Starter Forum Replies Last Post
Clone DAO Recordset into ADO Recordset kamrans74 VB How-To 0 March 6th, 2007 11:57 AM
converting recordset to array? carnevil00 Access VBA 8 October 2nd, 2006 02:43 PM
Recordset Into Array ~ How do I do it? phungleon Classic ASP Databases 2 May 13th, 2004 01:25 PM
Convert ADO recordset to DAO recordset andrew_taft Access 1 May 5th, 2004 02:31 PM
Converting recordset to an array satellite360 Classic ASP Basics 1 February 3rd, 2004 05:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.