rocky48 Posted December 29, 2014 Share Posted December 29, 2014 I am trying to write some code to display the visits to my site each week in batches of 13 weeks (1 quarter). I am getting the Week No and the number of hits, but the actual date, which is in a separate table is not being displayed. I have tried LEFT JOIN and INNER Join and even RIGHT JOIN (this only displays the Date). I can't see where I am going wrong! Here is the code: <? include('connect_visits.php'); doDB7(); $limitStart = $_POST['QUARTER'] - 13; $Visit_data="SELECT Visits.ID, Visits.WVisits, Visits.WCom, WeekNo.WNo, WeekNo.WCom FROM Visits LEFT JOIN WeekNo ON Visits.ID = WeekNo.WCom ORDER BY Visits.ID LIMIT {$limitStart}, 13"; $Visit_data_res = mysqli_query($mysqli, $Visit_data) or die(mysqli_error($mysqli)); $display_block = " <table width=\"20%\" cellpadding=\"3\" cellspacing=\"1\" border=\"1\" BGCOLOR=\"white\" > <tr> <th>Week No</th> <th>Week Commencing</th> <th>Visits</th> </tr>"; while ($C_info = mysqli_fetch_array($Visit_data_res)) { $Cid = $C_info['ID']; $Visits = ($C_info['WVisits']); $WeekNo = ($C_info['WCom']); //add to display $display_block .= " <tr> <td width=\"1%\" valign=\"top\">".$Cid."<br/></td> <td width=\"8%\" valign=\"top\">".$WeekNo."<br/></td> <td width=\"5%\" valign=\"top\">".$Visits."<br/></td> </td></tr>"; } mysqli_free_result($Visit_data_res); ?> Where am I going wrong? Link to comment https://forums.phpfreaks.com/topic/293500-left-join-data-not-displayed/ Share on other sites More sharing options...
Barand Posted December 29, 2014 Share Posted December 29, 2014 ON Visits.ID = WeekNo.WCom Are you sure those are the correct columns for your join? Link to comment https://forums.phpfreaks.com/topic/293500-left-join-data-not-displayed/#findComment-1501063 Share on other sites More sharing options...
rocky48 Posted December 29, 2014 Author Share Posted December 29, 2014 When I statred to write a reply to you, I realised my error. I was trying to JOIN ON to the date and not the foriegn key in the table. Many thanks! Link to comment https://forums.phpfreaks.com/topic/293500-left-join-data-not-displayed/#findComment-1501065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.