Jump to content

Using a variable in a link


Adzyboy

Recommended Posts

hey,I've been using php and mysql to code my site (well, I'm using the mx-system, but my own blocks at least), and I've come across a problem.Code Below

<?$query="SELECT * FROM episodes";$result=mysql_query($query);$num=mysql_numrows($result); ?><table width="100%" cellpadding="2" cellspacing="2" class="forumline">	<thead>		<caption>		<table border="0" cellspacing="0" cellpadding="0" width="100%" class="forumheader">			<tr>				<td align="left" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_left.gif" width="19" height="22" alt="" />				</td>				<td align="left" class="forumheader-mid">					Episodes				</td>				<td align="right" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_right.gif" width="19" height="22" alt="" />				</td>			</tr>		</table>		</caption>	</thead>	<tbody>		<tr> 			<th>ID</th>			<th>Season/Episode</th>			<th>Title</th>		</tr>		<?		$i=0;			while ($i < $num) {				$ID=mysql_result($result,$i,"ID");				$Season=mysql_result($result,$i,"Season");				$Episode=mysql_result($result,$i,"Episode");				$Title=mysql_result($result,$i,"Title");		?>		<tr>			<td class="row1"><span class="gensmall"><a href="index.php?page=5&episode="<? echo '$ID'; ?>""><? echo "$ID"; ?></a></span></td>			<td class="row1"><span class="gensmall">Season <? echo "$Season"; ?>, Episode <? echo "$Episode"; ?></span></td>			<td class="row1"><span class="gensmall"><? echo "$Title" ?></span></td>		</tr>		<?			++$i;			}		?>			</tbody></table>

Now, what is wrong is, I want the Episode ID to appear in the <a> link, so I can use the GET function on the next page to take all info out of the db where the id is equal to that.what actually happens is, when the link is meant to say for example

.../index.php?page=5&episode=101

with the text saying the same episode id (101 in this case)what is actually said is

.../index.php?page=5&episode=101

the text is still there though saying that episode id.I can't think of a reason as to why this is happening.Any help would be appreciated.Aaronerm.. actually I sorted this out.I changed the bit I struggled with to this:

<a href="index.php?page=5&episode=<? echo "$ID"; ?>">

I just looked at it on after I posted it on here and wondered why I put them there.thanks anyhow.

Link to comment
Share on other sites

<?$query="SELECT * FROM episodes";$result=mysql_query($query);?><table width="100%" cellpadding="2" cellspacing="2" class="forumline">	<thead>		<caption>		<table border="0" cellspacing="0" cellpadding="0" width="100%" class="forumheader">			<tr>				<td align="left" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_left.gif" width="19" height="22" alt="" />				</td>				<td align="left" class="forumheader-mid">					Episodes				</td>				<td align="right" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_right.gif" width="19" height="22" alt="" />				</td>			</tr>		</table>		</caption>	</thead>	<tbody>		<tr>			<th>ID</th>			<th>Season/Episode</th>			<th>Title</th>		</tr>		<?		$i=0;		  while($res = mysql_fetch_array($result)){				$ID=$res['ID'];				$Season=$res['Season'];;				$Episode=$res['Episode'];				$Title=$res['Title'];		?>		<tr>			<td class="row1"><span class="gensmall"><a href="index.php?page=5&episode=<? echo $ID; ?>"><? echo $ID; ?></a></span></td>			<td class="row1"><span class="gensmall">Season <? echo $Season; ?>, Episode :<? echo $Episode; ?></span></td>			<td class="row1"><span class="gensmall"><? echo "$Title" ?></span></td>		</tr>		<?			 }		?>			</tbody></table>

Link to comment
Share on other sites

Cheers for that.I have another problem now.I'm making the link to send the user to another page, where I use the $_GET variable to retrieve what the data is in the episode variable in the url.I get a problem when I try that page thoFatal error: Call to undefined function: array() in /home/adzyboy/public_html/episodes2.php on line 4the page is below:

<?$episodeid=$_GET('episodeid');mysql_query("SELECT * from episodes WHERE ID='%$episodeid'");$ID=mysql_result("ID");$Season=mysql_result("Season");$Episode=mysql_result("Episode");$Title=mysql_result("Title");$Air_Date=mysql_result("Air Date");$Writer=mysql_result("Writer");$Director=mysql_result("Director");$Star=mysql_result('Star');$Guest_Star=mysql_result('Guest Star');$Notes=mysql_result('Notes');$Quotes=mysql_result('Quotes');$Reviews=mysql_result('Reviews');$TV_Rating=mysql_result('TV Rating');$Site_Rating=mysql_result('.net Rating');?><table width="100%" cellpadding="2" cellspacing="2" class="forumline">	<thead>		<caption>		<table border="0" cellspacing="0" cellpadding="0" width="100%" class="forumheader">			<tr>				<td align="left" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_left.gif" width="19" height="22" alt="" />				</td>				<td align="left" class="forumheader-mid">					Season <? echo "$Season" ?> :: Episode <? echo "$Episode" ?> 				</td>				<td align="right" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_right.gif" width="19" height="22" alt="" />				</td>			</tr>		</table>		</caption>	</thead>	<tbody>		<tr>			<th><? echo "$Title" ?></th>		</tr>		<tr>			<td class="row2">				<b>Episode Number</b> - <? echo "$ID" ?><br />				<b>Original Air Date</b> - <? echo "$Air_Date" ?><br />				<b>Director</b> - <? echo "$Director" ?><br />				<b>Writer</b> - <? echo "$Writer" ?><br />				<b>Star</b> - <? echo "$Star" ?><br />				<b>Guest Star</b> - <? echo "$Guest_Star" ?><br />			</td>		</tr>		<tr>			<th>Notes</th>			<td class="row2">				<? echo "$Notes" ?>			</td>		</tr>		<tr>			<th>Quotes</th>			<td class="row2">				<? echo "$Quotes" ?>			</td>		</tr>		<tr>			<th>Reviews</th>			<td class="row2">				<? echo "$Reviews" ?>			</td>		</tr>	</tbody></table>

I don't think I've done the mysql_result properly, but the rest seems fine.to sum it up, or to be clear, user goes to episodes.php, they click a link, say index.php?page=5&episode=101. on the page5 which is episodes2.php, I use the $_GET variable to retrieve the information that is contained in the episode variable in the url (in this case "101"), and use that episode id (101) to retrieve the information I need from the database.I don't know why it's coming up with that, kinda confusing.Help would be appreciated.Aaron

Link to comment
Share on other sites

<? echo "$Quotes" ?>..you do that on almost all of your echos. Two things:1) You forgot to end every single echo, which you do with a ;2) You dont need quotation marks to echo just variables, so you can remove those.

Link to comment
Share on other sites

<?$episodeid=$_GET['episodeid'];$query = mysql_query("SELECT * from episodes WHERE ID=$episodeid  LIMIT 1");while($res = mysql_fetch_assoc($query)){$ID=$res['ID'];$Season=$res['Season'];$Episode=$res['Episode'];$Title=$res['Title'];$Air_Date=$res['Air Date'];$Writer=$res['Writer'];$Director=$res['Director'];$Star=$res['Star'];$Guest_Star=$res['Guest Star'];$Notes=$res['Notes'];$Quotes=$res['Quotes'];$Reviews=$res['Reviews'];$TV_Rating=$res['TV Rating'];$Site_Rating=$res['.net Rating'];?><table width="100%" cellpadding="2" cellspacing="2" class="forumline">	<thead>		<caption>		<table border="0" cellspacing="0" cellpadding="0" width="100%" class="forumheader">			<tr>				<td align="left" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_left.gif" width="19" height="22" alt="" />				</td>				<td align="left" class="forumheader-mid">					Season <? echo $Season" ?> :: Episode <? echo $Episode" ?>				</td>				<td align="right" valign="bottom" width="19">					<img src="../templates/Getaway/images/hdr_right.gif" width="19" height="22" alt="" />				</td>			</tr>		</table>		</caption>	</thead>	<tbody>		<tr>			<th><? echo $Title; ?></th>		</tr>		<tr>			<td class="row2">				<b>Episode Number</b> - <? echo $ID; ?><br />				<b>Original Air Date</b> - <? echo $Air_Date; ?><br />				<b>Director</b> - <? echo $Director; ?><br />				<b>Writer</b> - <? echo $Writer; ?><br />				<b>Star</b> - <? echo $Star; ?><br />				<b>Guest Star</b> - <? echo $Guest_Star; ?><br />			</td>		</tr>		<tr>			<th>Notes</th>			<td class="row2">				<? echo $Notes; ?>			</td>		</tr>		<tr>			<th>Quotes</th>			<td class="row2">				<? echo $Quotes; ?>			</td>		</tr>		<tr>			<th>Reviews</th>			<td class="row2">				<? echo $Reviews ?>			</td>		</tr>	</tbody></table><? } ?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...