adamhhh Posted April 26, 2007 Share Posted April 26, 2007 Ok i have this problem with $query2, <? //$document_id = $_REQUEST['document_id']; //echo $document_id; $document_id = 110; $host = ""; $user = ""; $password = ""; $database = ""; $connection = mysql_connect($host,$user,$password) or die ("Couldn't connect to server."); $db = mysql_select_db($database, $connection) or die ("Couldn't select database."); $query = "SELECT * FROM sections WHERE document_id = $document_id"; $result = mysql_query($query) or die ("This entry hasn't been found."); while($row = mysql_fetch_array($result)) { $section_heading = $row['section_heading']; $section_id = $row['section_id']; //echo "<strong> $section_heading,</strong>"; //echo $section_id; $query1 = "SELECT * FROM fragments WHERE section_id = $section_id ORDER BY date_created"; $result1 = mysql_query($query1) or die ("This entry hasn't been found."); while($row1 = mysql_fetch_array($result1)) { $fragment_heading = $row1['fragment_heading']; $date_created = $row1['date_created']; //echo "<a href=\"index.php?section_id=$section_id&document_type_id=2\">$fragment_heading</a>"; //echo "<br />"; //echo $date_created; $dateArray=explode('-',$date_created); // $dateArray[0]= 2007 // $dateArray[1] = 02 // $dateArray[2] = 05 $start_date = date('Y-m-d', mktime(0, 0, 0, $dateArray[1], $dateArray[2], $dateArray[0])); echo $start_date; $test = $dateArray[1]; //echo $test; $end_date = $test - 6; if ($end_date < 1) { $new_end_date = $end_date + 12; $dateArray[0] --; //echo $new_year; //echo $end_date; echo "<br />"; //echo $new_end_date; $new_end_date2 = "0" . $new_end_date; //echo $new_end_date2; $date1 = $dateArray[1] . $new_end_date2 . $dateArray[0]; echo "<br />"; //echo $date1; //$today = date("j, n, Y") $new_date = date('Y-d-m', mktime(0, 0, 0, $dateArray[1], $new_end_date2, $dateArray[0])); // $new_date is the end date we use echo $new_date; } $new_date = $new_date1; $start_date = $start_date1; $query2 = "SELECT * FROM fragments WHERE section_id = $section_id AND date_created BETWEEN $new_date1 AND $start_date1"; echo $query2; $result2 = mysql_query($query2) or die ("This entry hasn't been found."); while($row2 = mysql_fetch_array($result2)) { $fragment_heading = $row2['fragment_heading']; $date_created = $row2['date_created']; //echo "<a href=\"index.php?section_id=$section_id&document_type_id=2\">$fragment_heading</a>"; echo "<br />"; echo $fragment_heading; } } } ?> hmm at the moment its nearly working, however im a bit confused as in $query2 im looking at the $section_id (of which there are multiple) and $new_date and $start_date (1 of each). Ive retrieved the $new_date and $start_date from the database so they are i think 2007-09-26 and 2006-03-26. However I cannot get the query to run so its multiple section ids based on one of each $start_date and $new_date. Any ideas?? At the moment when I test the query it gets multiple start and finish dates based on multiple section ids. I need multiple section ids based on 1 start and 1 end date. ??? Link to comment https://forums.phpfreaks.com/topic/48752-solved-multiplesingle-query-confusion/ Share on other sites More sharing options...
adamhhh Posted April 26, 2007 Author Share Posted April 26, 2007 ok problem not solved, i thought it was Link to comment https://forums.phpfreaks.com/topic/48752-solved-multiplesingle-query-confusion/#findComment-238950 Share on other sites More sharing options...
fenway Posted April 26, 2007 Share Posted April 26, 2007 At the moment when I test the query it gets multiple start and finish dates based on multiple section ids. I need multiple section ids based on 1 start and 1 end date. ??? Sounds like you need an IN clause for section_id. Link to comment https://forums.phpfreaks.com/topic/48752-solved-multiplesingle-query-confusion/#findComment-238991 Share on other sites More sharing options...
adamhhh Posted April 26, 2007 Author Share Posted April 26, 2007 ah thanks Link to comment https://forums.phpfreaks.com/topic/48752-solved-multiplesingle-query-confusion/#findComment-239044 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.