probleem met een form en een resultaat op dezelfde page
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
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
<?php
error_reporting(E_ALL);
include("connection.php");
if(isset($_POST['Graphic']) &&
$_POST['Graphic'] == 'yes')
{
$result1 = "graphic";
}
if(isset($_POST['Interactive']) &&
$_POST['Interactive'] == 'yes')
{
$result2 = "interactive";
}
if(isset($_POST['Websites']) &&
$_POST['Websites'] == 'yes')
{
$result3 = "websites";
}
if(isset($_POST['Personal']) &&
$_POST['Personal'] == 'yes')
{
$result4 = "personal";
}
if((!isset($_POST['Graphic']) &&
$_POST['Graphic'] = 'yes')
and(!isset($_POST['Interactive']) &&
$_POST['Interactive'] = 'yes')
and(!isset($_POST['Websites']) &&
$_POST['Websites'] = 'yes')
and(!isset($_POST['Personal']) &&
$_POST['Personal'] = 'yes'))
{
$result1 = "graphic";
$result2 = "interactive";
$result3 = "websites";
$result4 = "personal";
}
$order = $_POST['group1'];
$result = mysql_query("SELECT * FROM jake_portfolio WHERE CAT = '$result1' OR CAT = '$result2' OR CAT ='$result3' OR CAT = '$result4' ORDER BY $order LIMIT 0,4");
$checked = "checked";
$num_rows = mysql_num_rows($result);
?>
error_reporting(E_ALL);
include("connection.php");
if(isset($_POST['Graphic']) &&
$_POST['Graphic'] == 'yes')
{
$result1 = "graphic";
}
if(isset($_POST['Interactive']) &&
$_POST['Interactive'] == 'yes')
{
$result2 = "interactive";
}
if(isset($_POST['Websites']) &&
$_POST['Websites'] == 'yes')
{
$result3 = "websites";
}
if(isset($_POST['Personal']) &&
$_POST['Personal'] == 'yes')
{
$result4 = "personal";
}
if((!isset($_POST['Graphic']) &&
$_POST['Graphic'] = 'yes')
and(!isset($_POST['Interactive']) &&
$_POST['Interactive'] = 'yes')
and(!isset($_POST['Websites']) &&
$_POST['Websites'] = 'yes')
and(!isset($_POST['Personal']) &&
$_POST['Personal'] = 'yes'))
{
$result1 = "graphic";
$result2 = "interactive";
$result3 = "websites";
$result4 = "personal";
}
$order = $_POST['group1'];
$result = mysql_query("SELECT * FROM jake_portfolio WHERE CAT = '$result1' OR CAT = '$result2' OR CAT ='$result3' OR CAT = '$result4' ORDER BY $order LIMIT 0,4");
$checked = "checked";
$num_rows = mysql_num_rows($result);
?>
<div id="workpreview">
<div id="previewimage"><a href="view.php?ID="><img src="../images/" border="0px"/> </a></div>
<div id="previewtitle"><a href="view.php?ID="> </a></div>
<div id="previewdesc"><a href="view.php?ID="> </a></div>
</div>
</div>
<div id="filtermenu">
<form action="portfolio.php" method="post">
<b> Search:</b>
<br/><br/>
<input name="Graphic" type="checkbox" value="yes" />
Graphic<br />
<input name="Interactive" type="checkbox" value="yes"/>
Interactive<br />
<input name="Websites" type="checkbox" value="yes" />
Websites<br />
<input name="Personal" type="checkbox" value="yes"/>
Personal
</p>
<br/><b>Sort by:</b><br/><br/>
<input name="group1" type="radio" value="DATE DESC"
Code (php)
Newest<br />
<input name="group1" type="radio" value="DATE ASC" />
Oldest<br />
<input name="group1" type="radio" value="VIEWS" />
Most viewed</p>
<input name="Search!" type="submit" value="Filter" id="button"/>
</form><br/>
</div>
Nu het probleem, ik wil dus dat als er geen form results zijn, de $result aan mijn while loop doorgeeft alles weer te geven, maar in deze manier vinkt hij wel alle checkboxes aan maar geeft hij toch geen result. Hoe fix ik dit?
Gebruik a.u.b. [code][/code]-tags
Jake rowsell op 08/10/2011 15:49:44:
Alvast bedankt voor het kijken. Ik ben bezig met een website waarop ik een form en een resultaat op dezelfde page heb, dit is om een soort zoekfunctie te creeren. Door middel van checkboxes zie je wat er geselecteerd is. Nu wil ik dat als ik op de pagina kom alle resultaten worden weergegeven. Mijn script is dit:
Nu het probleem, ik wil dus dat als er geen form results zijn, de $result aan mijn while loop doorgeeft alles weer te geven, maar in deze manier vinkt hij wel alle checkboxes aan maar geeft hij toch geen result. Hoe fix ik dit?
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
error_reporting(E_ALL);
include("connection.php");
if(isset($_POST['Graphic']) &&
$_POST['Graphic'] == 'yes')
{
$result1 = "graphic";
}
if(isset($_POST['Interactive']) &&
$_POST['Interactive'] == 'yes')
{
$result2 = "interactive";
}
if(isset($_POST['Websites']) &&
$_POST['Websites'] == 'yes')
{
$result3 = "websites";
}
if(isset($_POST['Personal']) &&
$_POST['Personal'] == 'yes')
{
$result4 = "personal";
}
if((!isset($_POST['Graphic']) &&
$_POST['Graphic'] = 'yes')
and(!isset($_POST['Interactive']) &&
$_POST['Interactive'] = 'yes')
and(!isset($_POST['Websites']) &&
$_POST['Websites'] = 'yes')
and(!isset($_POST['Personal']) &&
$_POST['Personal'] = 'yes'))
{
$result1 = "graphic";
$result2 = "interactive";
$result3 = "websites";
$result4 = "personal";
}
$order = $_POST['group1'];
$result = mysql_query("SELECT * FROM jake_portfolio WHERE CAT = '$result1' OR CAT = '$result2' OR CAT ='$result3' OR CAT = '$result4' ORDER BY $order LIMIT 0,4");
$checked = "checked";
$num_rows = mysql_num_rows($result);
?>
<?php
while($row = mysql_fetch_array($result)){ ?>
<div id="workpreview">
<div id="previewimage"><a href="view.php?ID=<?php echo $row['ID']; ?>"><img src="../images/<?php echo $row['IMG']; ?>" border="0px"/> </a></div>
<div id="previewtitle"><a href="view.php?ID=<?php echo $row['ID']; ?>"><?php echo $row['TITLE']; ?> </a></div>
<div id="previewdesc"><a href="view.php?ID=<?php echo $row['ID']; ?>"><?php echo $row['DESCR']; ?> </a></div>
</div>
<?php }; ?>
</div>
<div id="filtermenu">
<form action="portfolio.php" method="post">
<b> Search:</b>
<br/><br/>
<input name="Graphic" type="checkbox" value="yes" <?PHP if($result1 == 'graphic'){print $checked ; }?>/>
Graphic<br />
<input name="Interactive" type="checkbox" value="yes"<?PHP if($result2 == 'interactive'){print $checked ; }?>/>
Interactive<br />
<input name="Websites" type="checkbox" value="yes" <?PHP if($result3 == 'websites'){print $checked ; }?>/>
Websites<br />
<input name="Personal" type="checkbox" value="yes"<?PHP if($result4 == 'personal'){print $checked ; }?>/>
Personal
</p>
<br/><b>Sort by:</b><br/><br/>
<input name="group1" type="radio" value="DATE DESC" <?PHP if($order == 'DATE DESC'){print $checked ; } elseif($order != 'DATE ASC' or 'VIEWS'){print $checked ;}?>/>
Newest<br />
<input name="group1" type="radio" value="DATE ASC" <?PHP if($order== 'DATE ASC'){print $checked ; }?>/>
Oldest<br />
<input name="group1" type="radio" value="VIEWS" <?PHP if($order == 'VIEWS'){print $checked ; }?>/>
Most viewed</p>
<input name="Search!" type="submit" value="Filter" id="button"/>
</form><br/>
</div>
error_reporting(E_ALL);
include("connection.php");
if(isset($_POST['Graphic']) &&
$_POST['Graphic'] == 'yes')
{
$result1 = "graphic";
}
if(isset($_POST['Interactive']) &&
$_POST['Interactive'] == 'yes')
{
$result2 = "interactive";
}
if(isset($_POST['Websites']) &&
$_POST['Websites'] == 'yes')
{
$result3 = "websites";
}
if(isset($_POST['Personal']) &&
$_POST['Personal'] == 'yes')
{
$result4 = "personal";
}
if((!isset($_POST['Graphic']) &&
$_POST['Graphic'] = 'yes')
and(!isset($_POST['Interactive']) &&
$_POST['Interactive'] = 'yes')
and(!isset($_POST['Websites']) &&
$_POST['Websites'] = 'yes')
and(!isset($_POST['Personal']) &&
$_POST['Personal'] = 'yes'))
{
$result1 = "graphic";
$result2 = "interactive";
$result3 = "websites";
$result4 = "personal";
}
$order = $_POST['group1'];
$result = mysql_query("SELECT * FROM jake_portfolio WHERE CAT = '$result1' OR CAT = '$result2' OR CAT ='$result3' OR CAT = '$result4' ORDER BY $order LIMIT 0,4");
$checked = "checked";
$num_rows = mysql_num_rows($result);
?>
<?php
while($row = mysql_fetch_array($result)){ ?>
<div id="workpreview">
<div id="previewimage"><a href="view.php?ID=<?php echo $row['ID']; ?>"><img src="../images/<?php echo $row['IMG']; ?>" border="0px"/> </a></div>
<div id="previewtitle"><a href="view.php?ID=<?php echo $row['ID']; ?>"><?php echo $row['TITLE']; ?> </a></div>
<div id="previewdesc"><a href="view.php?ID=<?php echo $row['ID']; ?>"><?php echo $row['DESCR']; ?> </a></div>
</div>
<?php }; ?>
</div>
<div id="filtermenu">
<form action="portfolio.php" method="post">
<b> Search:</b>
<br/><br/>
<input name="Graphic" type="checkbox" value="yes" <?PHP if($result1 == 'graphic'){print $checked ; }?>/>
Graphic<br />
<input name="Interactive" type="checkbox" value="yes"<?PHP if($result2 == 'interactive'){print $checked ; }?>/>
Interactive<br />
<input name="Websites" type="checkbox" value="yes" <?PHP if($result3 == 'websites'){print $checked ; }?>/>
Websites<br />
<input name="Personal" type="checkbox" value="yes"<?PHP if($result4 == 'personal'){print $checked ; }?>/>
Personal
</p>
<br/><b>Sort by:</b><br/><br/>
<input name="group1" type="radio" value="DATE DESC" <?PHP if($order == 'DATE DESC'){print $checked ; } elseif($order != 'DATE ASC' or 'VIEWS'){print $checked ;}?>/>
Newest<br />
<input name="group1" type="radio" value="DATE ASC" <?PHP if($order== 'DATE ASC'){print $checked ; }?>/>
Oldest<br />
<input name="group1" type="radio" value="VIEWS" <?PHP if($order == 'VIEWS'){print $checked ; }?>/>
Most viewed</p>
<input name="Search!" type="submit" value="Filter" id="button"/>
</form><br/>
</div>
Nu het probleem, ik wil dus dat als er geen form results zijn, de $result aan mijn while loop doorgeeft alles weer te geven, maar in deze manier vinkt hij wel alle checkboxes aan maar geeft hij toch geen result. Hoe fix ik dit?
Toevoeging op 08/10/2011 15:55:20:
Zo?
ini_set('display_errors', 1); // 0 = uit, 1 = aan
error_reporting(E_ALL);
Regels 25 t/ 38 zijn dubbelop.
Foutafhandeling ontbreekt.
Denk ook aan SQL-Injection want een waarde uit een formulier kan altijd anders zijn dan jij verwacht.
Gewijzigd op 08/10/2011 16:04:33 door - SanThe -
Toevoeging op 08/10/2011 16:16:35:
santhe je bent een ster :D door de display errors af te gaan en met wat code te schuiven is het gelukt! thanks!
Gewijzigd op 08/10/2011 16:11:54 door jake rowsell
Ik denk dat wat je nu hebt niet eens werkt als je niet alle checkboxen aanvinkt.