Jump to content

[SOLVED] Please help - i'm stumped


giraffemedia

Recommended Posts

this works for me

 

<?php
session_start();

include ('../config.php');
include ('../opendb.php');

if(!isset($_SESSION['Login'])){

header ("location:../login.php");
  }

$record = $_GET['id'];

$bf_record = $_GET['bf_id'];

$query="SELECT * FROM contacts JOIN booking_form ON contacts_id = bf_company_id WHERE contacts_id = $record";
$result=mysql_query($query);
if(!$result) {
	print("Query Error: ".mysql_error());
}
// put all issues booked into a comma seperated string
$iss = '';
while($row = mysql_fetch_assoc($result)){
$iss .= $row['bf_issues_booked'];
$iss .= ',';
}
// Get rid of the last comma
$iss = trim($iss, ",");
// make an array out of the string
$bf_issues_booked = explode(",", $iss);
//get all the issues available
$issues_query="SELECT * FROM issues WHERE issue_on_sale BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 400 DAY)";
//echo $issues_query;
$issues_result=mysql_query($issues_query);
//echo mysql_num_rows($issues_result);

if(!$issues_result) {

echo("Query Error: ".mysql_error());

}

// A loop used to populate my form with the checkboxes and issue name, number etc. This works fine

while($irow=mysql_fetch_assoc($issues_result)) {
// check to see if the issue is in the booked array
$selected = in_array($irow['issue_number'], $bf_issues_booked) ? "checked=\"checked\"" : "";


$issues[] = '<input name="issue_number[]" type="checkbox" value="' .$irow['issue_number']. '" tabindex="11" ' . $selected . ' />Issue <strong>' .$irow['issue_number'] . '</strong> ' . $irow['issue_month'] . ' ' . $irow['issue_year'] ;



}

// A function set up to poulate a table with values returned from the above loop
function issues_table($data, $details="")
{
$sret = "<table ".$details.">\n";

$all = count($data)-1;

for($i=0; $i <= $all; $i++)
{
	if(($i % 2)==0)
	{
		$sret .= "<tr><td>".$data[$i]."</td>";
	}
	else
	{
		$sret .= "<td>".$data[$i]."</td></tr>\n";
	}
}
//	Catch if an odd cell
if(($all % 2) == 0)
{
	$sret .= "<td><br></td></tr>\n";
}

$sret .= "</table>\n";
return $sret;
}

$data = $issues;

echo issues_table($data, "border='0' width='100%'");
?>

</body>

</html>

 

Ray

A question about this topic. I am doing something similar

 

You are storing different 'issues' as such '1,15,21,32,55'

How would you do about searching for all the records that have the issue '15'.

 

You cannot just go, because your issues column is more then likely a varchar, so 15 <> '1,15,21,32,55'

SELECT * FROM table WHERE issues = '15'

 

So how would you go about searching for the all the users who have a certain issue?

 

In order to do something like that you would use the LIKE Function. Also you would need to add an end comma to you comma separated values. Reason for all this is quite simple. you have to look for "15," and not "15", because what happens when you get to issue 150?? Also you need the comma at the end because what if issue 15 is the last one?? It will be "15" not "15,".

 

SELECT * FROM table WHERE issues LIKE '%15,%'

 

Ray

Ray, for some reason all the results are being returned for a customer, not just from one booking form. If I have 3 or 4 booking forms all the values are selected. Does this have something to do with the JOIN in the SELECT query?

 

It's working(ish) now though which means we're getting somewhere!

 

James

Figured it out Ray, I changed the SELECT query from...

 

$query="SELECT * FROM contacts JOIN booking_form ON contacts_id = bf_company_id WHERE contacts_id = $record";

 

to...

 

$query="SELECT * FROM contacts JOIN booking_form ON contacts_id = bf_company_id WHERE contacts_id = $record AND bf_id = $bf_record";

 

and it work fine. Thanks for all your hard work, I really, really appreciate it!!

 

Regards

 

James

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.