Richzilla Posted March 1, 2007 Share Posted March 1, 2007 Hi crew, been stuck on this statement for 2 days now!! I want to pull data from my sql database and display it in a nice table. I've done this fine so far, however I'm getting stuck when some of the data is missing. Essentially I want to miss out columns if ther is no data there. I can't get this to work. Here's the code I'm using - <td class="trk_list_main" width="19%"><a href="<? echo $download1 ?>">part 1</a><br> <? if ($download2==""); break; else; <a href="<? echo $download2 ?>">part 2</a> ?> I get an unexpected else error in my browser when running my file. As I hope you can see from the code I want to use the download 1 link (this is always present) and then pass over the download 2 option if the cell is empty. I'm not sure of how to get this to work. I'm sure it's a very simple concept that I'm not approaching from the right angle. Please help me. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 here lies the proble th ";" with if and else statement if ($download2==""); break; else; chande it to if ($download2=="") break; else Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 That hasn't fixed it. Still get the - Parse error: parse error, unexpected T_ELSE in Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 can u post the code and the line no where you are getting this error... Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2007 Share Posted March 1, 2007 A break cannot be used with an if. The easiest option would be.... <?php if (!$download2 == ""); echo "<a href=\"$download2\">part 2</a>"; ?> Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 Here's part of the code. No need to post up the rest as I know that it works. It's for a music site I'm building. The error occurs on the line in red <tr> <td class="trk_list_main" width="21%"><? echo $dj ?></td> <td class="trk_list_main" width="29%"><? echo $event ?> </td> <td class="trk_list_main" width="16%"><? echo $date ?></td> <td class="trk_list_main" width="19%"><a href="<? echo $download1 ?>">part 1</a><br> <? if ($download2==""); break; else <a href="<? echo $download2 ?>">part 2</a> ?> <td class="trk_list_main" width="15%"><a href=/tracklist.php>Tracklist</a></td> </tr> Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 still you haven't removed the ";" from if statement... if ($download2==""); change this to if ($download2=="") Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 A break cannot be used with an if. The easiest option would be.... <?php if (!$download2 == ""); echo "<a href=\"$download2\">part 2</a>"; ?> That isn't good as i get the download 2 text with a link to my site root. I want to remove this text and link if i have no link. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 if ($download2 != "") echo "<a href=\"$download2\">part 2</a>"; Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 if ($download2 != "") echo "<a href=\"$download2\">part 2</a>"; <? if ($download2 != "") echo "<a href=\"$download2\">part 2"; ?> C'est magnifique. Thank you so much . I was close to going mental with this coding!!! Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 Sorry to reopen this thread. I'm progressing now which is great. I want now to add the tracklists to these dj mixes that I'm putting up. I want to link to a page that will pull the data from the database by using the url. Each song file has its own number in the db, so if i setupa script that uses the url as the source of the data to pull will this work?? Also I'm trying to generate links as thus - <td class="trk_list_main" width="15%"> <? if ($tracklist != "") echo "<a href=\ $tlist.$id \" target="_blank">"Tracklist <br> </td> </tr>"; i get this error message - Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in 1. Is what I'm trying to do the right way to do it? 2. What's wrong with this script? 3. Is there any decent php sites where I can learn more in depth scripting at a level i need as opposed to the simple php sites that I've found so far? Thanks team. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 $tlist="tracklist.php?" <td class="trk_list_main" width="15%"> <? if ($tracklist != "") echo "<a href=\ $tlist.$id \">"Tracklist <br> </td> </tr>"; use this:: <?php $tlist="tracklist.php?"; // a semocolon was missing ?> <td class="trk_list_main" width="15%"> <?php if ($tracklist != "") echo "<a href='$tlist.$id'>Tracklist </a><br> </td> </tr>"; // some parse error were there... ?> Quote Link to comment Share on other sites More sharing options...
trq Posted March 1, 2007 Share Posted March 1, 2007 Is there any decent php sites where I can learn more in depth scripting at a level i need You might try here. Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 Sorry ignore the previous peply use this <?php $tlist="tracklist.php?"; // a semocolon was missing ?> <td class="trk_list_main" width="15%"> <?php if ($tracklist != "") echo "<a href='$tlist$id'>Tracklist </a><br> </td> </tr>"; // some parse error were there... ?> Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 thanks very much. it's very frustrating when i can't get the syntax correct. I must have tried 50 different combinations to try and get it right!!! Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 was it solved.... Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 yes thanks so much. i can now generate urls from the id number of the item. Question is now through, how do i dynamcially generate the tracklist page from the url? the url has id redord of the text i want, but how do i tell the php to grab the info from the url? Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 1, 2007 Share Posted March 1, 2007 then instead of this $tlist="tracklist.php?"; use this $tlist="tracklist.php?id="; then url wull be like... tracklist.php?id=1 now you can get the value of id from url as $id = ''; if(isset($_GET['id'])) $id = $_GET['id']; Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 Thanks for the response. I'm confused. Where does - $id = ''; if(isset($_GET['id'])) $id = $_GET['id']; Go in the script? Here's my script that I've hacked together - <? $username="xxxx"; $password="xxxx"; $database="xxxx"; mysql_connect("xxx",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Mixes WHERE id=($_GET['id']); $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $dj=mysql_result($result,$i,"dj"); $event=mysql_result($result,$i,"event"); $date=mysql_result($result,$i,"date"); $tracklist=mysql_result($result,$i,"tracklist"); ?> <p class="trk_list_headers"> <u><? echo $dj ?>Tracklist</u> <p class="trk_list_main"><?php echo $tracklist; ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 1, 2007 Share Posted March 1, 2007 Please repost the code you're having problems with again between tags. Ken Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 I've had a further plan arround and I think i'm getting very close. Here's the codes again. I have this in my header <? $id = ''; if(isset($_GET['id'])) $id = $_GET['id']; $username="xxxx"; $password="xxxx"; $database="xxxx"; mysql_connect("xxxx",$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM Mixes WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); $i=0; while ($i < $num) { $dj=mysql_result($result,$i,"dj"); $event=mysql_result($result,$i,"event"); $date=mysql_result($result,$i,"date"); $tracklist=mysql_result($result,$i,"tracklist"); ?> <title><? echo $dj ?></title> The I have this further down in the body - <p class="trk_list_headers"> <u><? echo $dj?> Tracklist</u><br /> <p class="trk_list_main"><? echo $tracklist ?> <p class="trk_list_main"> <br /> I get this error message when running the script - Parse error: parse error, unexpected $ on line 100 Line 100 is the final </html> tag on the page!!! ANy help would be great. I've been trying to get this to work for hours now!!! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 1, 2007 Share Posted March 1, 2007 Do you ever close this loop? <?php while ($i < $num) { $dj=mysql_result($result,$i,"dj"); $event=mysql_result($result,$i,"event"); $date=mysql_result($result,$i,"date"); $tracklist=mysql_result($result,$i,"tracklist"); ?> Ken Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 1, 2007 Author Share Posted March 1, 2007 sorted. This little fella was causing issues for me - $i=0; while ($i < $num) { Quote Link to comment Share on other sites More sharing options...
itsmeArry Posted March 2, 2007 Share Posted March 2, 2007 have you incremented $i in while loop otherwise it will go in infinite loop Quote Link to comment Share on other sites More sharing options...
Richzilla Posted March 2, 2007 Author Share Posted March 2, 2007 Hi guys, I got the code to work eventually. Thanks for the help. I have 1 more problem. I'm trying to use my css to give my outputs consistency with the rest of the site. The code that I'm processing in the tracklist has html tags in it to list the output. I'm only using <br> and <p> tags. When the css reaches anything after a <p> tag it stops formatting the text and leaves it in the most standard format. I've treid using $i++. But it makes no difference. Any ideas why <p> is stopping the css formating? 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.