string sql probleem
ik zit met het volgende probleem: , ik heb in mijn db een tabal wrox_messages met daarin een kolom topic_name en een kolom message.
nu wil ik als ik de topics weergeef ook weergeven wat het laatst geposte bericht was.
nu zit ik met het probleem dat als de topic name een aanhalingsteken bevat, dat de query niet kan uitgevoerd worden.
ik hoop dat je het een beetje begrijpt wat mijn probleem is.
hieronder nog even mijn script.
groetjs jonas
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
error_reporting(E_ALL);
$forum_id = $_POST['forum_id'];
$page = $_POST['page'];
mysql_connect("sql205.byethost10.com","b10_3322909","gameover") or die ("geen connectie naar mysql");
mysql_select_db("b10_3322909_yourgamerpage") or die ("geen database gevonden");
//make query
if ($page = "1"){
$page = ($page * "10");
$query = "SELECT TOPIC_ID, TOPIC_NAME FROM WROX_TOPICS WHERE FORUM_ID=$forum_id ORDER BY TIME DESC LIMIT 0,$page";
}else{
$startpage = (($page-"1")*"10");
$endpage = ($page*"10");
$query = "SELECT TOPIC_ID, TOPIC_NAME FROM WROX_TOPICS WHERE FORUM_ID=$forum_id ORDER BY TIME DESC LIMIT $startpage,$endpage";
}
$result = mysql_query( $query ) or die (mysql_error());
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<topics>\n";
while ($row = mysql_fetch_array($result)){
$userlastquery = "SELECT TIME, USER FROM WROX_MESSAGES WHERE TOPIC_NAME= '". $row['TOPIC_NAME'] ."'ORDER BY TIME DESC LIMIT 0,1";
$userlastresult = mysql_query($userlastquery) or die (mysql_error());
$resultuserlast = mysql_fetch_array($userlastresult);
$counttopicsquery = "SELECT COUNT(MESSAGE_ID) FROM WROX_MESSAGES WHERE TOPIC_NAME= '".$row['TOPIC_NAME']. "'";
$counttopicsresult = mysql_query($counttopicsquery);
$counttopics = mysql_fetch_array($counttopicsresult);
echo "<topic>\n";
echo "<id>". $row['TOPIC_ID'] ."</id>\n";
echo "<topic_name>". $row['TOPIC_NAME'] ."</topic_name>\n";
echo "<time>". $resultuserlast['TIME']. "</time>\n";
echo "<lastuser>". $resultuserlast['USER']. "</lastuser>\n";
echo "<countmessages>". $counttopics['COUNT(MESSAGE_ID)'] . "</countmessages>\n";
echo "</topic>\n";
}
echo "</topics>\n";
?>
error_reporting(E_ALL);
$forum_id = $_POST['forum_id'];
$page = $_POST['page'];
mysql_connect("sql205.byethost10.com","b10_3322909","gameover") or die ("geen connectie naar mysql");
mysql_select_db("b10_3322909_yourgamerpage") or die ("geen database gevonden");
//make query
if ($page = "1"){
$page = ($page * "10");
$query = "SELECT TOPIC_ID, TOPIC_NAME FROM WROX_TOPICS WHERE FORUM_ID=$forum_id ORDER BY TIME DESC LIMIT 0,$page";
}else{
$startpage = (($page-"1")*"10");
$endpage = ($page*"10");
$query = "SELECT TOPIC_ID, TOPIC_NAME FROM WROX_TOPICS WHERE FORUM_ID=$forum_id ORDER BY TIME DESC LIMIT $startpage,$endpage";
}
$result = mysql_query( $query ) or die (mysql_error());
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<topics>\n";
while ($row = mysql_fetch_array($result)){
$userlastquery = "SELECT TIME, USER FROM WROX_MESSAGES WHERE TOPIC_NAME= '". $row['TOPIC_NAME'] ."'ORDER BY TIME DESC LIMIT 0,1";
$userlastresult = mysql_query($userlastquery) or die (mysql_error());
$resultuserlast = mysql_fetch_array($userlastresult);
$counttopicsquery = "SELECT COUNT(MESSAGE_ID) FROM WROX_MESSAGES WHERE TOPIC_NAME= '".$row['TOPIC_NAME']. "'";
$counttopicsresult = mysql_query($counttopicsquery);
$counttopics = mysql_fetch_array($counttopicsresult);
echo "<topic>\n";
echo "<id>". $row['TOPIC_ID'] ."</id>\n";
echo "<topic_name>". $row['TOPIC_NAME'] ."</topic_name>\n";
echo "<time>". $resultuserlast['TIME']. "</time>\n";
echo "<lastuser>". $resultuserlast['USER']. "</lastuser>\n";
echo "<countmessages>". $counttopics['COUNT(MESSAGE_ID)'] . "</countmessages>\n";
echo "</topic>\n";
}
echo "</topics>\n";
?>
Gewijzigd op 01/01/1970 01:00:00 door Jonas vermeulen
Kijk allereerst eens even naar de kleurtjes. Ik hoop niet dat dit er in jouw editor ook zo uitziet?
//if (isset($forum_id, $page)) {
naar:
if (isset($forum_id, $page)) {
en zet alles tusen [code tags
En je moet niet echo'en met " maar met '.