rocky48 Posted December 29, 2014 Share Posted December 29, 2014 (edited) 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? Edited December 29, 2014 by rocky48 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Solution rocky48 Posted December 29, 2014 Author Solution 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.