glassfish Posted October 17, 2014 Share Posted October 17, 2014 (edited) The Script: <?php include("connect.php"); ?> <?php echo "<h1>The Hashtag: </h1>"; if(isset($_GET['hashtag'])){ echo $_GET['hashtag']; } // Select the ID of the given hashtag from the "hashtags" table. $tqs = "SELECT `id` FROM `hashtags` WHERE `hashtag` = '" . $_GET['hashtag'] . "'"; $tqr = mysqli_query($dbc, $tqs) or die(mysqli_error($dbc)); $row = mysqli_fetch_assoc($tqr); // This prints e.g.: // 100 echo "<br/><br/>"; print_r($row['id']); // Select the threads from the "thread" table which contains the hashtag ID number. $tqs_two = "SELECT * FROM `thread` WHERE `hashtag_id` IN ('" . $row['id'] . "')"; $tqr_two = mysqli_query($dbc, $tqs_two) or die(mysqli_error($dbc)); $row_two = mysqli_fetch_assoc($tqr_two); echo "<br/><br/>"; print_r($row_two); ?> The script should select the rows by that ID number of the hashtag. It should look in the "hashtag_id" column of the table and see if that ID number can be found there, if it can be found there, then it should select that row. The ID numbers are inside that "hashtag_id" column separated by commas. Example: 98, 99, 100 My Question: How to do the SQL query so it selects the rows by the hashtag ID number? Edited October 17, 2014 by glassfish Quote Link to comment https://forums.phpfreaks.com/topic/291885-sql-query-to-select-a-row-by-an-id-number-out-of-a-column/ Share on other sites More sharing options...
Barand Posted October 17, 2014 Share Posted October 17, 2014 (edited) It was precisely to avoid this problem when I advised you to normalize you data correctly here http://forums.phpfreaks.com/topic/291641-store-the-id-number-inside-one-array-inside-for-loop/?do=findComment&comment=1493641 Edited October 17, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/291885-sql-query-to-select-a-row-by-an-id-number-out-of-a-column/#findComment-1494015 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.