我是PHP的新手,MySQL的基本级别以及HTML和ASP的基本级别。简而言之,我有一个MySQL数据库,我已经构建了一个SQL查询,它返回我想要的MySQL结果。
我想要学习的是建立一个网页:
基本上,我试图制作看起来像http://i.imgur.com/dwwGl.jpg
的东西并且在输出上也有相关的外观(我正在努力将格式化的消息部分转储到其他字段下方而不是旁边)。
这是我的MySQL查询。
SELECT tickets.ref AS `Ticket Number`
, concat_ws(' ', people.first_name, people.last_name) AS `User Name`
, DATE_FORMAT(tickets.date_created, get_format(DATE, 'EUR')) AS `Date/Time`
, left(tickets.subject, 80) AS Subject
, sec_to_time(tickets.total_to_first_reply) AS `Time 1st Response`
, sec_to_time(tickets.total_user_waiting) AS `Total Wait`
, mycleanup (left(tickets_messages.message, 250)) AS Message
FROM
tickets
INNER JOIN organizations
ON tickets.organization_id = organizations.id
INNER JOIN people
ON tickets.person_id = people.id AND people.organization_id = organizations.id
INNER JOIN tickets_messages
ON tickets_messages.ticket_id = tickets.id AND tickets_messages.person_id = people.id
WHERE
tickets.date_created > date_sub(now(), INTERVAL VARIABLEDAYS DAY)
AND organizations.name = VARIABLENAME
GROUP BY
tickets.ref
ORDER BY
`Date/Time`
正如我所说,这个有点混合,因为我需要帮助:
所以,任何想要帮助我完成这些任务的人,或者推荐一些我可以用来轻松生成这些内容的东西,而不必在每一个位上学习一门课程......我将不胜感激。
由于
威尔
答案 0 :(得分:1)
话虽如此,对这个问题的简洁而准确的答案是,你不能只让一个人在一组中解释整个问题。您应该从一些教程开始,或者检查一些现有代码,以了解它是如何工作的。 Stack Overflow对于细节来说是一个很好的资源,但不一定是这样的问题,除非碰巧被非常无聊的人看到,在问题被投票结束之前有很多时间写一个大的教程。
修改强>
显然你在这里输入正确的数据库凭证......
<?php
$db = new PDO('mysql:dbname=your-database-name;host=localhost', $username, $password);
$sql = $db->execute("SELECT `name` FROM `organizations` ORDER BY `name` ASC");
?>
<form id="user_form" action="" method="get">
<fieldset>
<select name="name">
<?php <?php while ($row = $sql->fetch(PDO::FETCH_OBJ)): ?>
<option value="<?php echo $row->name; ?>"><?php echo $row->name; ?></option>
<?php endwhile; ?>
</select>
<select name="days">
<option value="30">30</option>
<option value="60">60</option>
<option value="90">90</option>
</select>
<input type="submit" name="submit" value="submit">
</fieldset>
</form>
<?php
if(isset($_GET['days']) && isset($_GET['name'])):
$days = $_GET['days'];
$name = $_GET['name'];
$sql = $db->prepare('SELECT tickets.ref AS `ticket_number`
, concat_ws(' ', people.first_name, people.last_name) AS `username`
, DATE_FORMAT(tickets.date_created, get_format(DATE, 'EUR')) AS `datetime`
, left(tickets.subject, 80) AS `subject`
, sec_to_time(tickets.total_to_first_reply) AS `first_response`
, sec_to_time(tickets.total_user_waiting) AS `total_wait`
, mycleanup (left(tickets_messages.message, 250)) AS `message`
FROM
tickets
INNER JOIN organizations
ON tickets.organization_id = organizations.id
INNER JOIN people
ON tickets.person_id = people.id AND people.organization_id = organizations.id
INNER JOIN tickets_messages
ON tickets_messages.ticket_id = tickets.id AND tickets_messages.person_id = people.id
WHERE
tickets.date_created > date_sub(now(), INTERVAL :days DAY)
AND organizations.name = :name
GROUP BY
tickets.ref
ORDER BY
`Date/Time`');
$sql->bindParam('days', $days);
$sql->bindParam('name', $name);
$sql->execute();
/*
It looks like your data could be considered tabular, so we can make a table and drop the results in place...
*/
?>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th>Ticket Number</th>
<th>User Name</th>
<th>Date/Time</th>
<th>Subject</th>
<th>Time 1st Response</th>
<th>Total Wait</th>
<th>Message</th>
</tr>
<?php while ($row = $sql->fetch(PDO::FETCH_OBJ)): ?>
<tr>
<td><?php echo $row->ticket_number; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->datetime; ?></td>
<td><?php echo $row->subject; ?></td>
<td><?php echo $row->first_response; ?></td>
<td><?php echo $row->total_wait; ?></td>
<td><?php echo $row->message; ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php endif; ?>
当然所有这些都是未经测试的,最终是一个免费助手,所以我的保证是有限的。它应该指向一个可接受的程序补丁方向。
请注意我更改了您的查询结果名称,因为 - 虽然我实际上并不知道这一点 - 但我认为在对象名称中使用空格或字符并不是一个好主意。 (例如:SELECT名称AS User Name
意味着您将该对象作为$ row-&gt;用户名...在那里查看问题?)
另外,您应该按ID选择组织,而不是名称。由于我不知道该表的结构,所以我只是使用你指定的名称。如果要切换到id,请将组织选择更改为还包括id并在组织选择菜单的值部分中回显id。
除此之外,我认为我在这里完成了。我需要考虑在某个时候实际上有生命。
祝你好运。
答案 1 :(得分:0)
要完成此任务,请了解以下内容:
一旦你学会了用mysql_query(),我会建议你学习如何在PDO中这样做,出于安全考虑。