mysql rand()
bij elke auto staat het zelfde plaatje en als ik op f5 druk verandert hij
hoe kan dat?
ik wil dat het plaatje bij de goede auto staat
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
include("config.php");
if(! check_login()) {
header('Location: login.php');
exit;
}
$dbres = mysql_query("SELECT *,UNIX_TIMESTAMP(`pc`) AS `pc`,UNIX_TIMESTAMP(`transport`) AS `transport`,UNIX_TIMESTAMP(`bc`) AS `bc`,UNIX_TIMESTAMP(`slaap`) AS `slaap`,UNIX_TIMESTAMP(`kc`) AS `kc`,UNIX_TIMESTAMP(`start`) AS `start`,UNIX_TIMESTAMP(`crime`) AS `crime`,UNIX_TIMESTAMP(`ac`) AS `ac` FROM `users` WHERE `login`='{$_SESSION['login']}'");
$data = mysql_fetch_object($dbres);
if ($jisin == 1) {
header('Location: jisin.php');
}
$car = mysql_query("SELECT * FROM `cars` ORDER BY rand() LIMIT 0,1");
$autos = mysql_fetch_object($car);
$cars = mysql_query("SELECT * FROM `autos` ORDER BY rand() LIMIT 0,1");
$auto = mysql_fetch_object($cars);
$users = mysql_query("SELECT * FROM `autos` WHERE `login`='{$data->login}' ORDER BY rand() LIMIT 0,1");
$user = mysql_fetch_object($users);
?>
<style>
div#bg {
background-color: #c1bda4;
border-left: 1px solid #9c9984;
border-right: 1px solid #9c9984;
border-bottom: 1px solid #9c9984;
border-top: 1px solid #9c9984;
width: 500px;
height: auto;
}
div#menu_content {
background-color: #d1cdb5;
border-left: 1px solid #9c9984;
border-right: 1px solid #9c9984;
border-bottom: 1px solid #9c9984;
border-top: 0;
width: 500px;
height: 25px;
font-family:arial;
font-size:12px;
}
div#menu_links {
height: 26px;
float: left;
margin: 0px;
padding: 0px;
margin-left: 5px;
font-family:arial;
font-size:12px;
color: #000000;
}
a.two:link
{
color:#16130e;
text-decoration: none;
}
a.two:visited
{
color:#16130e;
text-decoration: none;
}
a.two:hover
{
color: #a4a193;
text-decoration: none;
}
div#info3 {
background-color: #c1bda4;
border-left: 1px solid #9c9984;
border-right: 1px solid #9c9984;
border-bottom: 1px solid #9c9984;
border-top: 1px solid #9c9984;
width: 500px;
height: auto;
text-align: left;
}
.maintext{
background-color: #023445;
border-left: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
width: 500px;
height: 25px;
font-family:arial;
font-size:12px;
color: white;
text-align: left;
padding-left:2px;
padding-top: 6px;
}
#font_car {
font-family:arial;
font-size:12px;
color: black;
text-align: left;
}
#border_car {
border-left: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
border-bottom: 1px solid #FFFFFF;
border-top: 1px solid #FFFFFF;
}
</style>
<link rel="stylesheet" type="text/css" href="voorbeeld.css">
<body>
<table cellpadding="0" cellspacing="0" width="500px"><tr><td>
<table width="500px" border="0" cellspacing="2" cellpadding="2" class="mod_list">
<div class="maintext"><div align="left">Garage.</div></div>
<div id="menu_content">
<div id="menu_links"><a href="index.php?a=garage&t=garage" class="two" >Garage</a></div>
<div id="menu_links">|</div>
<div id="menu_links"><a href="index.php?a=garage&t=verschepen" class="two" >Verschepen</a></div>
<div id="menu_links">|</div>
<div id="menu_links"><a href="index.php?a=garage&t=verkopen" class="two" >Verkopen</a></div>
<div id="menu_links">|</div>
<div id="menu_links"><a href="index.php?a=garage&t=crushen" class="two" >Crushen</a></div>
</div>
<?php
$dbres = mysql_query("SELECT * FROM autos WHERE login='$data->login' ORDER BY id");
while($list = mysql_fetch_object($dbres))
{
$naam = $naam[$list->soort];
$schade = $list->waarde/100;
$schadekosten = $list->schade*$schade;
$waarde = number_format($list->waarde-$schadekosten, 0, '.' , '.');
?>
<br>
<table border="1" bordercolor=white style="background-color:#dbd2b7; width="250px" height="90px" >
<tr>
<th width="50%" scope="row">
<div id="font_car">
Naam: <?echo$list->naam;?><br>
Id: <?echo$list->id;?><br>
Schade: <?echo$schade;?>%<br>
Schadekosten <?echo$schadekosten;?><br>
Waarde: <?echo$waarde;?>
</div>
</th>
<td width="50%">
<img src="<? echo $autos->url; ?>">
</td>
</tr>
</table>
<?
}
?>
include("config.php");
if(! check_login()) {
header('Location: login.php');
exit;
}
$dbres = mysql_query("SELECT *,UNIX_TIMESTAMP(`pc`) AS `pc`,UNIX_TIMESTAMP(`transport`) AS `transport`,UNIX_TIMESTAMP(`bc`) AS `bc`,UNIX_TIMESTAMP(`slaap`) AS `slaap`,UNIX_TIMESTAMP(`kc`) AS `kc`,UNIX_TIMESTAMP(`start`) AS `start`,UNIX_TIMESTAMP(`crime`) AS `crime`,UNIX_TIMESTAMP(`ac`) AS `ac` FROM `users` WHERE `login`='{$_SESSION['login']}'");
$data = mysql_fetch_object($dbres);
if ($jisin == 1) {
header('Location: jisin.php');
}
$car = mysql_query("SELECT * FROM `cars` ORDER BY rand() LIMIT 0,1");
$autos = mysql_fetch_object($car);
$cars = mysql_query("SELECT * FROM `autos` ORDER BY rand() LIMIT 0,1");
$auto = mysql_fetch_object($cars);
$users = mysql_query("SELECT * FROM `autos` WHERE `login`='{$data->login}' ORDER BY rand() LIMIT 0,1");
$user = mysql_fetch_object($users);
?>
<style>
div#bg {
background-color: #c1bda4;
border-left: 1px solid #9c9984;
border-right: 1px solid #9c9984;
border-bottom: 1px solid #9c9984;
border-top: 1px solid #9c9984;
width: 500px;
height: auto;
}
div#menu_content {
background-color: #d1cdb5;
border-left: 1px solid #9c9984;
border-right: 1px solid #9c9984;
border-bottom: 1px solid #9c9984;
border-top: 0;
width: 500px;
height: 25px;
font-family:arial;
font-size:12px;
}
div#menu_links {
height: 26px;
float: left;
margin: 0px;
padding: 0px;
margin-left: 5px;
font-family:arial;
font-size:12px;
color: #000000;
}
a.two:link
{
color:#16130e;
text-decoration: none;
}
a.two:visited
{
color:#16130e;
text-decoration: none;
}
a.two:hover
{
color: #a4a193;
text-decoration: none;
}
div#info3 {
background-color: #c1bda4;
border-left: 1px solid #9c9984;
border-right: 1px solid #9c9984;
border-bottom: 1px solid #9c9984;
border-top: 1px solid #9c9984;
width: 500px;
height: auto;
text-align: left;
}
.maintext{
background-color: #023445;
border-left: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
width: 500px;
height: 25px;
font-family:arial;
font-size:12px;
color: white;
text-align: left;
padding-left:2px;
padding-top: 6px;
}
#font_car {
font-family:arial;
font-size:12px;
color: black;
text-align: left;
}
#border_car {
border-left: 1px solid #FFFFFF;
border-right: 1px solid #FFFFFF;
border-bottom: 1px solid #FFFFFF;
border-top: 1px solid #FFFFFF;
}
</style>
<link rel="stylesheet" type="text/css" href="voorbeeld.css">
<body>
<table cellpadding="0" cellspacing="0" width="500px"><tr><td>
<table width="500px" border="0" cellspacing="2" cellpadding="2" class="mod_list">
<div class="maintext"><div align="left">Garage.</div></div>
<div id="menu_content">
<div id="menu_links"><a href="index.php?a=garage&t=garage" class="two" >Garage</a></div>
<div id="menu_links">|</div>
<div id="menu_links"><a href="index.php?a=garage&t=verschepen" class="two" >Verschepen</a></div>
<div id="menu_links">|</div>
<div id="menu_links"><a href="index.php?a=garage&t=verkopen" class="two" >Verkopen</a></div>
<div id="menu_links">|</div>
<div id="menu_links"><a href="index.php?a=garage&t=crushen" class="two" >Crushen</a></div>
</div>
<?php
$dbres = mysql_query("SELECT * FROM autos WHERE login='$data->login' ORDER BY id");
while($list = mysql_fetch_object($dbres))
{
$naam = $naam[$list->soort];
$schade = $list->waarde/100;
$schadekosten = $list->schade*$schade;
$waarde = number_format($list->waarde-$schadekosten, 0, '.' , '.');
?>
<br>
<table border="1" bordercolor=white style="background-color:#dbd2b7; width="250px" height="90px" >
<tr>
<th width="50%" scope="row">
<div id="font_car">
Naam: <?echo$list->naam;?><br>
Id: <?echo$list->id;?><br>
Schade: <?echo$schade;?>%<br>
Schadekosten <?echo$schadekosten;?><br>
Waarde: <?echo$waarde;?>
</div>
</th>
<td width="50%">
<img src="<? echo $autos->url; ?>">
</td>
</tr>
</table>
<?
}
?>
Overigens wil ik je aanraden om mysql_fetch_assoc() te gebruiken i.p.v. mysql_fetch_object(). Veel sneller en bovendien is een resultset geen object.
volgens mij is dit:
Code (php)
1
2
2
$car = mysql_query("SELECT * FROM cars ORDER BY rand() LIMIT 0,1");
$autos = mysql_fetch_object($car);
$autos = mysql_fetch_object($car);
niet goed
Gewijzigd op 01/01/1970 01:00:00 door thymen akker