turpentyne Posted February 23, 2012 Share Posted February 23, 2012 I'm sure this is possible, I'm just not sure how. I have a query for queries from a category_table in the database. When it pulls to the page, I want to loop through each row found and do a query "where category = 1etc" to a second_table for records matching, then print the results of the second query out. Or is there a way to pull the queries from query1 through the while statement that contains query 2? I've gotten this far and I'm getting this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in /home/workshop/public_html/workshopsb.php on line 10 which is a little confusing, because I had nothing on line 10. Moved things around to see where that line was, but it always says line 10? <?php include("dbx.php"); $query1 = mysql_query("select * from tbl_cat"); while ($row = mysql_fetch_array($query1)) { echo $row['cat_id']."<br>x<br>"; $query2 = "select * from tbl_workshops where category={$row['cat_id']}"; @$result_all = mysql_query($query2); $catid = {$row['cat_id']} $catname = {$row['cat_name']} echo $catname." Workshops"; while ($c_row = mysql_fetch_array($result_all)){ $story=$c_row['workshop_description']; ?> <td> <b><?= $c_row['workshop_title'] ?></b><br /><br /> <?php echo implode(" ", array_slice(preg_split("/\s+/", $story), 0, 100));?>....<br /><br /> <a href="workshop.php?id=<?= $c_row['workshop_id'] ?>">Read more and Register</a> <br /><br /> <div class="line-separator"></div> <br /><br /> <? $catid = ""; $catname = ""; } //end while } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257625-semi-autogenerate-variables-can-i/ Share on other sites More sharing options...
Maq Posted February 23, 2012 Share Posted February 23, 2012 Don't suppress errors. Remove the '@' symbol and I'll bet you get an error for this line. If that is the case then it's probably an issue with your query. Post the new error first. @$result_all = mysql_query($query2); Quote Link to comment https://forums.phpfreaks.com/topic/257625-semi-autogenerate-variables-can-i/#findComment-1320418 Share on other sites More sharing options...
batwimp Posted February 23, 2012 Share Posted February 23, 2012 You're missing some semicolons after you initialize $catid and $catname; Quote Link to comment https://forums.phpfreaks.com/topic/257625-semi-autogenerate-variables-can-i/#findComment-1320427 Share on other sites More sharing options...
turpentyne Posted February 23, 2012 Author Share Posted February 23, 2012 ah... ok, I've added in errors, and added the two colons batwimp found. I'm still getting the same error, though? <?php include("dbx.php"); $query1 = "select * from tbl_cat"; $result_cats = mysql_query($query1) or die(mysql_error()); while ($row = mysql_fetch_array($result_cats)) { echo $row['cat_id']."<br>x<br>"; $query_selectall = "select * from tbl_workshops where category={$row['cat_id']}"; $result_all = mysql_query($query_selectall) or die(mysql_error()); $catid = {$row['cat_id']}; $catname = {$row['cat_name']}; echo $catname." Workshops"; while ($c_row = mysql_fetch_array($result_all)){ $story=$c_row['workshop_description']; ?> <td> <b><?= $c_row['workshop_title'] ?></b><br /><br /> <?php echo implode(" ", array_slice(preg_split("/\s+/", $story), 0, 100));?>....<br /><br /> <a href="workshop.php?id=<?= $c_row['workshop_id'] ?>">Read more and Register</a> <br /><br /> <div class="line-separator"></div> <br /><br /> <? $catid = ""; $catname = ""; } //end while } ?> Quote Link to comment https://forums.phpfreaks.com/topic/257625-semi-autogenerate-variables-can-i/#findComment-1320432 Share on other sites More sharing options...
turpentyne Posted February 23, 2012 Author Share Posted February 23, 2012 wait.. gah! Hold that thought a moment. I wasn't dropping the file in the right folder. I was Parse error: syntax error, unexpected '{' in /home/workshop/public_html/workshopsb.php on line 15 I took those out, and so far it looks like it works... sometimes its the simplest damned mistakes! Quote Link to comment https://forums.phpfreaks.com/topic/257625-semi-autogenerate-variables-can-i/#findComment-1320436 Share on other sites More sharing options...
Drummin Posted February 23, 2012 Share Posted February 23, 2012 Shouldn't these lines be... <b><?php echo " {$c_row['workshop_title']}" ?></b><br /><br /> <?php echo implode(" ", array_slice(preg_split("/\s+/", $story), 0, 100));?>....<br /><br /> <a href="workshop.php?id=<?php echo "{$c_row['workshop_id']}" ?>">Read more and Register</a> Quote Link to comment https://forums.phpfreaks.com/topic/257625-semi-autogenerate-variables-can-i/#findComment-1320440 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.