freelancer Posted February 18, 2007 Share Posted February 18, 2007 Hey freaks, I would like to know how can be this kinda script developed where for example here: http://www.overload-gaming.org/v3/clanwars/index.php I have my own script where you can add items to database tables, and then selecting them at other page, but I would like to create same as in this page above, where you also view/add details to another link, like var's comes as index.php?page=matches&id=2. Can someone give any tutorial or lead me Hope you understand what i meant Thanks Quote Link to comment Share on other sites More sharing options...
JJohnsenDK Posted February 18, 2007 Share Posted February 18, 2007 i dont understand your request... plz explain futher... Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 18, 2007 Author Share Posted February 18, 2007 I just want to know what I have to do, to create this kind results adding script where I can also write details about war, and this comes in new page and has got different id Quote Link to comment Share on other sites More sharing options...
trq Posted February 18, 2007 Share Posted February 18, 2007 If you allready know how to execute queries then this kind of thing is easy. Say you have a table (articles). CREATE TABLE articles ( id INT PRIMARY KEY, title VARCHAR(80), data TEXT ); Now, on list.php you would create a query that selects all titles and id's. In your while loop, you create links to detail.php. eg; <?php while ($row = mysql_fetch_assoc($result)) { echo "<a href='detail.php?id={$row['id']}'>{$row['title']}</a><br />"; } ?> Then.... on detail.php you run a query to retrieve the data associated with the id passed through the url (of course you neeed to sanitise the data first). eg; <?php $sql = "SELECT data FROM articles WHERE id = '{$_GET['id']}'"; ?> Hope that helps. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 18, 2007 Author Share Posted February 18, 2007 Thanks mate I figured it out and it works, but now I got problem like this : when I add something to table, then at my page where is link to details, link is corrent ( id=1 ), now when I add second record, url to this goes also correctly ( id=2 ), but now if I delete first record, then in any url id goes to same. How I can fix this? Quote Link to comment Share on other sites More sharing options...
trq Posted February 18, 2007 Share Posted February 18, 2007 Post the relevent code. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 18, 2007 Author Share Posted February 18, 2007 This is first page, where you can go to details page <?php include("config.php"); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM results ORDER BY id DESC"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="0" cellpadding="2" class="results"> <tr align="left"> <th width="61">Date</th> <th width="98">Opponent</th> <th width="67">Map</th> <th width="65">Score</th> <th width="104">Type</th> <th align="center">Details</th> </tr> <?php while ($row = mysql_fetch_assoc($result)) { $i=0; while ($i < $num) { $res=mysql_result( $result,$i,"res"); $date=mysql_result($result,$i,"date"); $opponent=mysql_result($result,$i,"opponent"); $map=mysql_result($result,$i,"map"); $score=mysql_result($result,$i,"score"); $type=mysql_result($result,$i,"type"); // $info=mysql_result($result,$i,"info"); $details=mysql_result($result,$i,"details"); // Color variables switch($res) { case 'Win' : $status = "#008000"; break; case 'Lost' : $status = "#FF0000"; break; case 'Draw' : $status = "#CC9900"; break; } echo "<tr align=\"left\">"; echo "<td>$date</td>"; echo "<td>$opponent</td>"; echo "<td>$map</td>"; echo "<td><font color=\"$status\">$score</font></td>"; echo "<td>$type</font></td>"; echo "<td><center><a target=\"_blank\" href='detail.php?id={$row['id']}'><img border=\"0\" src=\"images/icon/Arrow.gif\"></a><center></td>"; echo "</tr>"; $i++; } } echo "</table>"; ?> Here is detail.php: <?php include("admin/config.php"); @mysql_select_db($database) or die( "Unable to select database"); $sql=" SELECT details FROM results WHERE id='{$_GET['id']}'"; $result2=mysql_query($sql); $num=mysql_numrows($result2); mysql_close(); $i=0; while ($i < $num) { $detailshow=mysql_result($result2,$i,"details"); echo $detailshow; $i++; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 18, 2007 Share Posted February 18, 2007 thorpe your code example so good but what he's asking how to add 2 id's to one user as what i understand. if that's true then when a user join's the site then you have to enter a random number to a int field then use that as a second id just an idear. The use of a random number is becouse you can not set the database to increment more then once. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 18, 2007 Author Share Posted February 18, 2007 I'm doing it in one table also, doesn't this affect Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 18, 2007 Author Share Posted February 18, 2007 Hey I fixed it, I added $id=mysql_result($result,$i,"id"); and to table url href='detail.php?id=$id' now It works as I want, but how I can include it in my web, not in different window? Or how could this look if I want url with 2 variables like index.php?page=results&id=$id ? Quote Link to comment Share on other sites More sharing options...
trq Posted February 18, 2007 Share Posted February 18, 2007 If you want it in the same page removed the target="_blank" from the url. The rest I'm afraid your going to need to come up with yourself. A big part of programming is learning to think. Youve been handed a pretty simple example, just build on that. PS; In your results page. If your only expecting one record (which you are) you should not use a while() loop. Quote Link to comment Share on other sites More sharing options...
freelancer Posted February 18, 2007 Author Share Posted February 18, 2007 Well yes I know that I have to remove blank, but thank you anyway, I'll figure it out Solved 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.