Jump to content

semi-autogenerate variables? can I?


turpentyne

Recommended Posts

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
}
  ?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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
}
  ?>

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.