使用PHP / MySQL创建动态链接 [英] Creating Dynamic Links with PHP/MySQL

查看:105
本文介绍了使用PHP / MySQL创建动态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建我的第一个PHP / MySQL网站,我很难弄清楚如何生成动态链接并为这些链接创建新页面。

i'm creating my first PHP/MySQL site and i'm having difficulty figuring out how to generate dynamic links and creating a new page for those links.

我的索引页面从我的数据库中提取某些细节作为预览,当访问者点击该项目时,我希望它们被带到一个页面,该页面显示该行的数据库的完整信息。

My index page is pulling in certain details from my database as a preview, and when the visitor clicks on that item, i want them to be taken to a page which shows the full information from the database for that row.

我的索引页面上用于显示预览的代码如下,任何有关修改它以生成链接和页面的帮助都将非常感谢。

The code on my index page for displaying the previews is below, any help on amending it to generate the link and page would be greatly appreciated.

<?php
$query="SELECT * FROM $tbl_name ORDER BY job_id DESC";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;
while ($i < $num) {

$f1=mysql_result($result,$i,"company_name");
$f2=mysql_result($result,$i,"job_title");
$f3=mysql_result($result,$i,"city");
$f4=mysql_result($result,$i,"country");
$job_id=mysql_result($result,$i,"job_id");
?>

<div class = "hjl">
<ul>
<li id = "jobtitle"><?php echo $f2; ?></li><br />
<li id = "compname"><?php echo $f1; ?></li>
</ul>

<ul>
<li id = "city"><?php echo $f3; ?>, <?php echo $f4; ?></li><br />
</ul>

</div>

<?php
$i++;
}
?>

我很确定我的要求非常简单,我无法得到我的不停地回答它。

I'm pretty sure what i'm asking is really simple, i just can't get my head around acheieving it.

推荐答案

感谢您的回答,但我已设法修复它(或解决方法)它)在我的索引页面上:

Thanks to you both for your answers, but i have managed to fix it (or work-around it) with this on my index page:

<?php

$query="SELECT * FROM $tbl_name ORDER BY job_id DESC";
$result=mysql_query($query) or die(mysql_error());
$rsjobinfo=mysql_fetch_assoc($result);

mysql_close();

do {?>
<div class = "hjl"><a href="paging.php?job_id=<?php echo $rsjobinfo['job_id'];?>">
<ul>
<li id = "jobtitle"><?php echo $rsjobinfo['job_title'];?></li><br />
<li id = "compname"><?php echo $rsjobinfo['company_name'];?></li>
</ul>
<ul>
<li id = "city"><?php echo $rsjobinfo['city'];?>, 
    <?php echo    $rsjobinfo['country'];?></li>
</ul>
</a>
</div>
<?php } while ($rsjobinfo=mysql_fetch_assoc($result))?>

</div>

在我的内容页面上显示:

Followed by this on my content page:

<?php
$job_id = $_GET['job_id'];

$query="SELECT * FROM $tbl_name WHERE job_id = $job_id";
$result=mysql_query($query) or die(mysql_error());
$rsjobinfo=mysql_fetch_assoc($result);

mysql_close();

?>

感谢大家的帮助。

这篇关于使用PHP / MySQL创建动态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆