TheCatapult Posted April 8, 2012 Share Posted April 8, 2012 Hello friends, I just want to ask if it possible to have something like this: index.php?id=1 to select the content in ID 1. Here's my code. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>TCB | Online Streaming | </title> <style type="text/css">#div{ background-color: #669999; width: 450px; font-family:"Arial", Times, serif; text-align:justify;}#news{ width: 450px; height: 450px; background-color: #99ffff; position: absolute; top: 500px; left: 0px;</style></head><body><div id="news"><div><img border="0" src="headline.jpg" alt="Programs" width="451" height="82"> <?$username="";$password="";$database="";mysql_connect("",$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM news ORDER BY id DESC LIMIT 3";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();?><?$i=0;while ($i < $num) {$bck = ($i % 2 == 0 ) ? " style=\"background:#A3FFA3\"" : " style=\"background: #B7B7E8;\"";$id=mysql_result($result,$i,"id");$title=mysql_result($result,$i,"title");$content=mysql_result($result,$i,"content");$poster=mysql_result($result,$i,"poster");?><div id="div" <? echo $bck ?>> <? echo $id;?><a href="\http://www.mywebsite.com/index.php?id=$id\"><b><? echo $title</a>;?></b></a> <br>$i++;} ?></div></div>[/body] But the link does not work, too.Parse error: syntax error, unexpected '/' in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/index.html on line 144 Now pls help me to have ?id=N Thanks! Link to comment Share on other sites More sharing options...
Don E Posted April 8, 2012 Share Posted April 8, 2012 <a href="\http://www.mywebsite.com/index.php?id=$id\"><b><? echo $title</a>;?></b></a> <br> The / is because of the highlight above. In order to get the $id to work, you can try something like: <? echo '<a href="http://www.mywebsite.com/index.php?id=' . $id . '"><b>' . $title . '</b></a> <br/>'; ?> Link to comment Share on other sites More sharing options...
TheCatapult Posted April 9, 2012 Author Share Posted April 9, 2012 Hi, When I click the link for example: http://www.mywebsite.com/index.php?id=30 It does not show the $title, $content and $poster of each id. How to do that? I'm sorry for my English. Thanks! Link to comment Share on other sites More sharing options...
birbal Posted April 9, 2012 Share Posted April 9, 2012 in that page you need to catch the $_GET['id'] and have to pass it in WHERE clause with select statement to catch appropiate data from database. after that you can fetch the results. Link to comment Share on other sites More sharing options...
TheCatapult Posted April 9, 2012 Author Share Posted April 9, 2012 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>TCB | Online Streaming | </title> <style type="text/css">#div{ background-color: #669999; width: 450px; font-family:"Arial", Times, serif; text-align:justify;}#news{ width: 450px; height: 450px; background-color: #99ffff; position: absolute; top: 500px; left: 0px;</style></head><body><div id="news"><div><img border="0" src="headline.jpg" alt="Programs" width="451" height="82"> <?$username="";$password="";$database="";mysql_connect("",$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM news ORDER BY id DESC LIMIT 3";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();?><?$username="741839_test";$password="building10";$database="741839_test";$_GET['id']mysql_connect("fdb3.eu.pn",$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM news ORDER BY id DESC LIMIT 3 WHERE id='id'";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();?><div id="div" <? echo $bck ?>> <? echo $id;?><a href="\http://www.mywebsite.com/index.php?id=$id\"><b><? echo $title</a>;?></b></a> <br>$i++;} ?></div></div>[/body] Not work. Parse error: syntax error, unexpected T_STRING in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/index.html on line 131 Link to comment Share on other sites More sharing options...
Ingolme Posted April 9, 2012 Share Posted April 9, 2012 This syntax is incorrect:<? echo $title</a>;?>You seem to have left these lines outside of a PHP block: $i++;} ?> Link to comment Share on other sites More sharing options...
TheCatapult Posted April 9, 2012 Author Share Posted April 9, 2012 Sorry for the code. It's not the code, actually. Here's the code. I have change but please help me because it still has an error on it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>TCB | Online Streaming | </title> <style type="text/css">#div{ background-color: #669999; width: 450px; font-family:"Arial", Times, serif; text-align:justify; a:link {text-decoration:none;} /* unvisited link */a:visited {text-decoration:none;} /* visited link */a:hover {text-decoration:underline;} /* mouse over link */a:active {text-decoration:underline;} /* selected link */}#news{a:link {text-decoration:none;} /* unvisited link */a:visited {text-decoration:none;} /* visited link */a:hover {text-decoration:underline;} /* mouse over link */a:active {text-decoration:underline;} /* selected link */ width: 450px; height: 450px; background-color: #99ffff; position: absolute; top: 500px; left: 0px;}</style></head><body><div id="news"><div><img border="0" src="headline.jpg" alt="Programs" width="451" height="82"> <?$username="";$password="";$database="";$id=mysql_result($result,$i,"id");mysql_connect("",$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM news ORDER BY id DESC LIMIT 3 WHERE id='$id'";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();?><?$i=0;while ($i < $num) {$bck = ($i % 2 == 0 ) ? " style=\"background:#A3FFA3\"" : " style=\"background: #B7B7E8;\"";$id=mysql_result($result,$i,"id");$title=mysql_result($result,$i,"title");$content=mysql_result($result,$i,"content");$poster=mysql_result($result,$i,"poster");?></body></html> Thanks! Link to comment Share on other sites More sharing options...
thescientist Posted April 9, 2012 Share Posted April 9, 2012 can you tell us the error and line number? is it still the same issue as your last post? Link to comment Share on other sites More sharing options...
thescientist Posted April 9, 2012 Share Posted April 9, 2012 $id=mysql_result($result,$i,"id"); where do $result and $i come from?you need a result set from mysql_query, and $i hasn't been defined.http://php.net/manua...ysql-result.php Link to comment Share on other sites More sharing options...
justsomeguy Posted April 9, 2012 Share Posted April 9, 2012 The while loop also isn't being closed, and you're not incrementing $i. Link to comment Share on other sites More sharing options...
TheCatapult Posted April 10, 2012 Author Share Posted April 10, 2012 Hi,What are the necessary codes?What lines should I put the necessary codes? Here's the problem. Parse error: syntax error, unexpected $end in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/news.php on line 58 Thank you very much! Link to comment Share on other sites More sharing options...
Ingolme Posted April 10, 2012 Share Posted April 10, 2012 Can you show your updated code? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 10, 2012 Share Posted April 10, 2012 I'm not going to just tell you the answer, but I'll help you figure it out. Look at the error message you posted, it says unexpected end. That means the code ended when the parser was not expecting it to. That means that you are missing a closing bracket in your code. Look at your code carefully and you'll see that you have an opening bracket without a closing one, so you need to add a closing bracket in the place that makes sense for what you're trying to do. Link to comment Share on other sites More sharing options...
TheCatapult Posted April 11, 2012 Author Share Posted April 11, 2012 I found it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>TCB | Online Streaming | </title> <style type="text/css">#div{ background-color: #669999; width: 450px; font-family:"Arial", Times, serif; text-align:justify; a:link {text-decoration:none;} /* unvisited link */a:visited {text-decoration:none;} /* visited link */a:hover {text-decoration:underline;} /* mouse over link */a:active {text-decoration:underline;} /* selected link */}#news{a:link {text-decoration:none;} /* unvisited link */a:visited {text-decoration:none;} /* visited link */a:hover {text-decoration:underline;} /* mouse over link */a:active {text-decoration:underline;} /* selected link */ width: 450px; height: 450px; background-color: #99ffff; position: absolute; top: 500px; left: 0px;}</style></head><body><div id="news"><div><img border="0" src="headline.jpg" alt="Programs" width="451" height="82"> <?$username="";$password="";$database="";$i=0;while ($i < $num) {}$id=mysql_result($result,$i,"id");mysql_connect("",$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query="SELECT * FROM news ORDER BY id DESC LIMIT 3 WHERE id='$id'";$result=mysql_query($query);$num=mysql_numrows($result);mysql_close();?><?$i=0;while ($i < $num) {}$bck = ($i % 2 == 0 ) ? " style=\"background:#A3FFA3\"" : " style=\"background: #B7B7E8;\"";$id=mysql_result($result,$i,"id");$title=mysql_result($result,$i,"title");$content=mysql_result($result,$i,"content");$poster=mysql_result($result,$i,"poster");?></body></html> The problems were: Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/news.php on line 43Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/news.php on line 53Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/news.php on line 54Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/news.php on line 55Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /srv/disk4/741839/www/catapultphpmysql.eu.pn/testwebsite/news.php on line 56 Thank you very much for help! Link to comment Share on other sites More sharing options...
thescientist Posted April 11, 2012 Share Posted April 11, 2012 that's odd, because that doesn't look it would work (or make sense) at all. or are you saying that those are errors you are still getting and don't know why? If that is the case (as imagine it must) it would be prudent to go through every line of the PHP code and be able to articulate exactly what the line does, and why it's there, so you can better understand what your code is doing (or isn't doing). Why are you using the first while loop? Do you know how/when to use a while loop?What value do you think you are getting with this line? $id=mysql_result($result,$i,"id") Do you know how mysql_query works? (specifically its return value?)Do you know how mysql_result works? Link to comment Share on other sites More sharing options...
Ingolme Posted April 11, 2012 Share Posted April 11, 2012 Do you understand what each line of your code is doing? Link to comment Share on other sites More sharing options...
TheCatapult Posted April 11, 2012 Author Share Posted April 11, 2012 I can understand somewhat but not all. mysql_query is to send a unique query. For example mysql_query('SELECT title FROM news');mysql_result is the one which result what mysql_query has queried. For example:$query=mysql_query('SELECT title from news');mysql_result=('$query'); I'm not sure. All I want is to have a single record. http://www.mywebsite.com/news.php?id=1 Thank you very much. Link to comment Share on other sites More sharing options...
Ingolme Posted April 11, 2012 Share Posted April 11, 2012 You must understand all of your code. If you just copy code from somewhere and put it on your page you'll never be able to debug it. Do you understand the purpose of curly braces {} or know what $i is for? Link to comment Share on other sites More sharing options...
TheCatapult Posted April 11, 2012 Author Share Posted April 11, 2012 Hi Inglome, Sorry for my slow understanding. {} I do not know. $i, I do not know. Please help me. Link to comment Share on other sites More sharing options...
thescientist Posted April 11, 2012 Share Posted April 11, 2012 the wonder of the internet is that you can look up what you don't know, rather than just guessing and not understanding. I can understand somewhat but not all. mysql_query is to send a unique query. For example mysql_query('SELECT title FROM news');mysql_result is the one which result what mysql_query has queried. For example:$query=mysql_query('SELECT title from news');mysql_result=('$query'); I'm not sure. All I want is to have a single record. http://www.mywebsite.com/news.php?id=1 Thank you very much. http://www.w3schools.com/php/php_mysql_select.asphttp://www.w3schools.com/php/func_mysql_query.asphttp://www.w3schools.com/php/func_mysql_result.asp Hi Inglome, Sorry for my slow understanding. {} I do not know. $i, I do not know. Please help me. http://www.w3schools.com/php/php_looping.asphttp://www.w3schools.com/php/php_variables.asp you should really take a step back and think exactly of what you are trying to do. blindly throwing code at the situation is not going to help you understand why and how programming works. So, write it out in steps, what you are trying to do. Then take each step and write out its equivalent in code. What you are trying to do is very simple, and all you are doing is complicating it by not trying understand it, thus furthering your own confusion. Link to comment Share on other sites More sharing options...
TheCatapult Posted April 12, 2012 Author Share Posted April 12, 2012 in that page you need to catch the $_GET['id'] and have to pass it in WHERE clause with select statement to catch appropiate data from database. after that you can fetch the results.Thanks thescientist, Inglome, justsomeguy, and birbal for your help. I'm just confused. I think I have done this before but I can't remember the procedure, selecting content by ID. Where will I put the select statement? Link to comment Share on other sites More sharing options...
astralaaron Posted April 12, 2012 Share Posted April 12, 2012 I'm just confused. I think I have done this before but I can't remember the procedure, selecting content by ID.Where will I put the select statement? I am not sure exactly what is confusing you. But the PHP pages read the code from top to bottom, so as long as you don't try to catch the id below the SQL then you are good.. If you do your select statement just like you have but just add in WHERE `id_field_name`=$id_variable it should work out Link to comment Share on other sites More sharing options...
Ingolme Posted April 12, 2012 Share Posted April 12, 2012 "SELECT" is an SQL command, but I advise that you go through the PHP tutorial first and learn and practise what you find there. Link to comment Share on other sites More sharing options...
TheCatapult Posted April 13, 2012 Author Share Posted April 13, 2012 Hi Inglome, I have searched and have read a few tutorials. I've been reading an article here: http://www.freewebmasterhelp.com/tutorials/phpmysql/6 To quote: Selecting A Single RecordAt the end of the last part of this tutorial, I showed you how to select records from the database based on the contents of partiular fields using: SELECT * FROM contacts WHERE field='value'Now, by using the unique ID field we can select any record from our database using: SELECT * FROM contacts WHERE id='$id'Where $id is a variable holding a number of a record. This may seem to be a little worthless as it is, but you can use this very effectively in a number of different ways. For example, if you wanted to have a dynamically generated site run through a database and a single PHP script, you could write the script to include the database data into the design. Then, using the id field, you could select each individual page and put it into the output. You can even use the page's URL to specify the record you want e.g. http://www.yoursite.com/news/items.php?item=7393And then have the PHP script look up the record with the id corresponding to $item, which in this case would be 7393 I really can't understand this. It has a variable $id but the tutorial does not say what must be on that variable. Or would that variable contain mysql_select ('SELECT * FROM id'). Thanks thanks and many thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted April 13, 2012 Share Posted April 13, 2012 The $id variable should hold the ID of the record you're trying to select, which in your case is what you get from $_GET. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.