View Full Version : Mysql help/PHP
Habtopia
20-12-2008, 02:04 PM
<?php
include("config.php");
include("opendb.php");
$get_cats = mysql_query("SELECT * FROM `categories` ORDER BY `displayorder`") or die(mysql_error());
$get_info = mysql_query("SELECT * FROM `systeminfo`") or die(mysql_error());
$info = mysql_fetch_array($get_info);
while($cats = mysql_fetch_array($get_cats)) {
$get_rares = mysql_query("SELECT * FROM `rares` WHERE `catid`='".$cats['id']."'") or die(mysql_error());
echo("<b><center><font face=verdana size=1> ".$cats['name']."</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info[stripe1];
$color2 = $info[stripe2];
$row_count = 0;
while($rare = mysql_fetch_array($get_rares)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td width="15%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><font face=verdana size=1><?php echo $rare['name']; ?></font><br><font face=verdana size=1><img alt="" src="<?php echo("".$info[imagepath]."".$rare['image'].""); ?>"><br><?php echo $rare['value']; ?> HC</font></td>
</td>
<?php
$row_count++;
if($row_count==6){
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count=0;
}
}
echo("</table><br>
");
}
?>
Is there anyway to make the rares be grabbed in order of there value?
Dentafrice
20-12-2008, 02:33 PM
Do you think your code could get any messier? I mean seriously.. have you never heard of indention?
Change your $get_rares query to this..
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
Should work.
Habtopia
20-12-2008, 02:44 PM
Do you think your code could get any messier? I mean seriously.. have you never heard of indention?
Change your $get_rares query to this..
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
Should work.
This was very helpful and got some kind of result, Only problem is its now ordering them by there first number
so kind of like
99 9 84 6 54
any ideas?, and thanks
Dentafrice
20-12-2008, 02:49 PM
What do you mean it is ordering them by their first number? Tad bit confused there ;P
Habtopia
20-12-2008, 02:51 PM
like it will go
94
93
9
84
7
64
if you get me
also...
www.habtopia.co.uk/values/show_rares.php (http://www.habtopia.co.uk/values/show_rares.php) should help you get what i mean
Excellent2
20-12-2008, 02:52 PM
So really you want to order them by their minimal value to highest value or visa versa?
Dentafrice
20-12-2008, 02:53 PM
I thought you wanted them in descending order (greatest to lowest).
If you want them to go:
90, 80, 70, 60, 50:
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
If you want them to go:
20, 30, 40, 50, 60
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` ASC" ) or die( mysql_error() );
Habtopia
20-12-2008, 02:57 PM
Still ordering them the same weird :S
<?php
include("config.php");
include("opendb.php");
$get_cats = mysql_query("SELECT * FROM `categories` ORDER BY `displayorder`") or die(mysql_error());
$get_info = mysql_query("SELECT * FROM `systeminfo`") or die(mysql_error());
$info = mysql_fetch_array($get_info);
while($cats = mysql_fetch_array($get_cats)) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo("<b><center><font face=verdana size=1> ".$cats['name']."</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info[stripe1];
$color2 = $info[stripe2];
$row_count = 0;
while($rare = mysql_fetch_array($get_rares)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td width="15%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><font face=verdana size=1><?php echo $rare['name']; ?></font><br><font face=verdana size=1><img alt="" src="<?php echo("".$info[imagepath]."".$rare['image'].""); ?>"><br><?php echo $rare['value']; ?> HC</font></td>
</td>
<?php
$row_count++;
if($row_count==6){
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count=0;
}
}
echo("</table><br>
");
}
?>
www.habtopia.co.uk/values/show_rares.php
Dentafrice
20-12-2008, 03:00 PM
Okay try this.. we'll see what it's doing and I'll help you figure it out..
try this code.. save it and upload it.. then tell me and I'll look..
<?php
include ("config.php");
include ("opendb.php");
$get_cats = mysql_query( "SELECT * FROM `categories` ORDER BY `displayorder`" ) or die( mysql_error() );
$get_info = mysql_query( "SELECT * FROM `systeminfo`" ) or die( mysql_error() );
$info = mysql_fetch_array( $get_info );
while( $cats = mysql_fetch_array( $get_cats ) ) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo ("<b><center><font face=verdana size=1> " . $cats ['name'] . "</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info [stripe1];
$color2 = $info [stripe2];
$row_count = 0;
while( $rare = mysql_fetch_array( $get_rares ) ) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td id="<?php
echo $rare ["id"];
?>" width="15%" style="text-align:center;background-color:#<?php
echo $row_color;
?>"><font face=verdana size=1><?php
echo $rare ['name'];
?></font><br>
<font face=verdana size=1><img alt=""
src="<?php
echo ("" . $info [imagepath] . "" . $rare ['image'] . "");
?>"><br><?php
echo $rare ['value'];
?> HC</font></td>
</td>
<?php
$row_count ++;
if($row_count == 6) {
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count = 0;
}
}
echo ("</table><br>
");
}
?>
Habtopia
20-12-2008, 03:03 PM
its there on www.habtopia.co.uk/values/show_rares.php (http://www.habtopia.co.uk/values/show_rares.php)
and thanks for help so far
Is your database storeing the values as integers or strings? (I don't know too much about MySQL so forgive me if that was a silly question).
EDIT: I think you need to get the script to store them in the database as just numbers and get the php script to convert them to thrones and hcs etc.
Habtopia
20-12-2008, 03:30 PM
Is your database storeing the values as integers or strings? (I don't know too much about MySQL so forgive me if that was a silly question).
EDIT: I think you need to get the script to store them in the database as just numbers and get the php script to convert them to thrones and hcs etc.
If i could answer i would lol, do you know how to check
[I replied the second u edited HA]
The only solution I can think of without editing the script is to save the values as 001HCs 015HCs etc, but that would look quite bad.
Habtopia
20-12-2008, 04:13 PM
The only solution I can think of without editing the script is to save the values as 001HCs 015HCs etc, but that would look quite bad.
Yeah i though of that too but then thougt ud have to filter the '0s' somehow lol
Jackboy
20-12-2008, 07:41 PM
Yeah i though of that too but then thougt ud have to filter the '0s' somehow lol
Lookup explode() , I suppose that could be used. Something like that.
If you PMed me explaining what u want I would fix.
Lookup explode() , I suppose that could be used. Something like that.
If you PMed me explaining what u want I would fix.
I'm not sure that would work. This should:
$value = $row['valuesorwe'];
if(substr($value, 0, 2 == "00")
$value = substr($value, 2);
else if(substr($value, 0, 1 == "0")
$value = substr($value, 1);
echo $value;
Still a messy solution. The way they are added to the database should really be changed.
Habtopia
21-12-2008, 04:53 PM
I'm not sure that would work. This should:
$value = $row['valuesorwe'];
if(substr($value, 0, 2 == "00")
$value = substr($value, 2);
else if(substr($value, 0, 1 == "0")
$value = substr($value, 1);
echo $value;
Still a messy solution. The way they are added to the database should really be changed.
where in the script would this be inserted?
where in the script would this be inserted?
I think the quotes got messed up in the PMs.
<?php
include("config.php");
include("opendb.php");
$get_cats = mysql_query("SELECT * FROM `categories` ORDER BY `displayorder`") or die(mysql_error());
$get_info = mysql_query("SELECT * FROM `systeminfo`") or die(mysql_error());
$info = mysql_fetch_array($get_info);
while($cats = mysql_fetch_array($get_cats)) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo("<b><center><font face=verdana size=1> ".$cats['name']."</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info[stripe1];
$color2 = $info[stripe2];
$row_count = 0;
while($rare = mysql_fetch_array($get_rares)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td width="15%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><font face=verdana size=1><?php echo $rare['name']; ?></font><br><font face=verdana size=1><img alt="" src="<?php echo("".$info[imagepath]."".$rare['image'].""); ?>"><br>
<?php
$value = $rare['value'];
if(substr($value, 0, 2 == "00")
$value = substr($value, 2);
else if(substr($value, 0, 1 == "0")
$value = substr($value, 1);
echo $value;
?> HC</font></td>
</td>
<?php
$row_count++;
if($row_count==6){
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count=0;
}
}
echo("</table><br>
");
}
?>
Habtopia
21-12-2008, 06:35 PM
Parse error: syntax error, unexpected T_VARIABLE in /home/habjay/public_html/values/show_rares.php on line 23
<?php
include("config.php");
include("opendb.php");
$get_cats = mysql_query("SELECT * FROM `categories` ORDER BY `displayorder`") or die(mysql_error());
$get_info = mysql_query("SELECT * FROM `systeminfo`") or die(mysql_error());
$info = mysql_fetch_array($get_info);
while($cats = mysql_fetch_array($get_cats)) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo("<b><center><font face=verdana size=1> ".$cats['name']."</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info[stripe1];
$color2 = $info[stripe2];
$row_count = 0;
while($rare = mysql_fetch_array($get_rares)) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td width="15%" style="text-align:center;background-color:#<?php echo $row_color; ?>"><font face=verdana size=1><?php echo $rare['name']; ?></font><br><font face=verdana size=1><img alt="" src="<?php echo("".$info[imagepath]."".$rare['image'].""); ?>"><br>
<?php
$value = $rare['value'];
if(substr($value, 0, 2) == "00")
$value = substr($value, 2);
else if(substr($value, 0, 1) == "0")
$value = substr($value, 1);
echo $value;
?> HC</font></td>
</td>
<?php
$row_count++;
if($row_count==6){
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count=0;
}
}
echo("</table><br>
");
}
?>
Habtopia
21-12-2008, 08:32 PM
Gold Dragon
http://www.habtopia.co.uk/values/images/rares/dragon_gold.gif
9T 0 HCVenomous Habbulus
http://www.habtopia.co.uk/values/images/rares/monsterplant.gif
99.0 HCBlueberry Icm
http://www.habtopia.co.uk/values/images/rares/icm_blue.gif
89.0 HCStrawberry Icm
http://www.habtopia.co.uk/values/images/rares/icm_pink.gif
89 HCNavy Pillow
http://www.habtopia.co.uk/values/images/rares/pillow_navy.gif
84 HCValentines Cauldron
http://www.habtopia.co.uk/values/images/rares/cauldron.gif
8 HCSaturn Smoke
http://www.habtopia.co.uk/values/images/rares/smoke_yellow.gif
79 HCMercury Smoke
http://www.habtopia.co.uk/values/images/rares/smoke_white.gif
74 HCDirectors Chair
http://www.habtopia.co.uk/values/images/rares/hw_chair_2.gif
74 HCAqua Monolith
http://www.habtopia.co.uk/values/images/rares/mono_aqua.gif
7 HCPluto Smoke
http://www.habtopia.co.uk/values/images/rares/smoke_purple.gif
69 HCBronze Dragon
http://www.habtopia.co.uk/values/images/rares/dragon_bronze.gif
66 HCTurquoise Pillow
http://www.habtopia.co.uk/values/images/rares/pillow_aqua.gif
64 HCPink Pillow
http://www.habtopia.co.uk/values/images/rares/pillow_pink.gif
64 HCNeptune Smoke
http://www.habtopia.co.uk/values/images/rares/smoke_violet.gif
64 HCSkull Guitar
http://www.habtopia.co.uk/values/images/rares/gallery_guitar_2.gif
64 HCBlack Laser Gate
http://www.habtopia.co.uk/values/images/rares/laser_black.gif
6.8 HCTypo
http://www.habtopia.co.uk/values/images/rares/typo.gif
50 HCGold Laser
http://www.habtopia.co.uk/values/images/rares/laser_yellow.gif
5.5 HCVenus Smoke
http://www.habtopia.co.uk/values/images/rares/smoke_pink.gif
48 HCBlack Pillow
http://www.habtopia.co.uk/values/images/rares/pillow_black.gif
45 HCSky Dragon
http://www.habtopia.co.uk/values/images/rares/dragon_sky.gif
448 HCPink Monolith
http://www.habtopia.co.uk/values/images/rares/mono_pink.gif
40 HCBlue Sleeping Bag
http://www.habtopia.co.uk/values/images/rares/bag_blue.gif
Still ordering them wrong :(
Habtopia
21-12-2008, 10:09 PM
I now have them ordering correctly
i changed the type in sql from varchar to int....which wouldnt let me have decimal places.
so i set them as decimal and made it 5,1 to allow one decimal
only problem now is i want to filter out the .0 as its poitnless but to have 0.5 i need the decimal lol
example:
www.habtopia.co.uk/values/show_rares.php
Robbie
21-12-2008, 10:13 PM
$value = str_replace(".0", "", $value);
not looked at your code but yeah.
Habtopia
22-12-2008, 01:45 AM
Have tried this seem to do nothing?
any ideas anybody else
btw the code is
<?php
include ("config.php");
include ("opendb.php");
$get_cats = mysql_query( "SELECT * FROM `categories` ORDER BY `displayorder`" ) or die( mysql_error() );
$get_info = mysql_query( "SELECT * FROM `systeminfo`" ) or die( mysql_error() );
$info = mysql_fetch_array( $get_info );
while( $cats = mysql_fetch_array( $get_cats ) ) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo ("<b><center><font face=verdana size=1> " . $cats ['name'] . "</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info [stripe1];
$color2 = $info [stripe2];
$row_count = 0;
while( $rare = mysql_fetch_array( $get_rares ) ) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td id="<?php
echo $rare ["id"];
?>" width="15%" style="text-align:center;background-color:#<?php
echo $row_color;
?>"><font face=verdana size=1><?php
echo $rare ['name'];
?></font><br>
<font face=verdana size=1><img alt=""
src="<?php
echo ("" . $info [imagepath] . "" . $rare ['image'] . "");
?>"><br><?php
echo $rare ['value'];
?> HC</font></td>
</td>
<?php
$row_count ++;
if($row_count == 6) {
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count = 0;
}
}
echo ("</table><br>
");
}
?>
Have tried this seem to do nothing?
any ideas anybody else
btw the code is
<?php
include ("config.php");
include ("opendb.php");
$get_cats = mysql_query( "SELECT * FROM `categories` ORDER BY `displayorder`" ) or die( mysql_error() );
$get_info = mysql_query( "SELECT * FROM `systeminfo`" ) or die( mysql_error() );
$info = mysql_fetch_array( $get_info );
while( $cats = mysql_fetch_array( $get_cats ) ) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo ("<b><center><font face=verdana size=1> " . $cats ['name'] . "</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info [stripe1];
$color2 = $info [stripe2];
$row_count = 0;
while( $rare = mysql_fetch_array( $get_rares ) ) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td id="<?php
echo $rare ["id"];
?>" width="15%" style="text-align:center;background-color:#<?php
echo $row_color;
?>"><font face=verdana size=1><?php
echo $rare ['name'];
?></font><br>
<font face=verdana size=1><img alt=""
src="<?php
echo ("" . $info [imagepath] . "" . $rare ['image'] . "");
?>"><br><?php
echo $rare ['value'];
?> HC</font></td>
</td>
<?php
$row_count ++;
if($row_count == 6) {
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count = 0;
}
}
echo ("</table><br>
");
}
?>
You can't just put it in there you really should learn some bsic php knowledge and if my way was ordering wrong you must have forgotten to put the 0s when you were inserting them.
<?php
include ("config.php");
include ("opendb.php");
$get_cats = mysql_query( "SELECT * FROM `categories` ORDER BY `displayorder`" ) or die( mysql_error() );
$get_info = mysql_query( "SELECT * FROM `systeminfo`" ) or die( mysql_error() );
$info = mysql_fetch_array( $get_info );
while( $cats = mysql_fetch_array( $get_cats ) ) {
$get_rares = mysql_query( "SELECT * FROM `rares` WHERE `catid`='{$cats ['id']}' ORDER BY `value` DESC" ) or die( mysql_error() );
echo ("<b><center><font face=verdana size=1> " . $cats ['name'] . "</font></center></b><br>
<table width=\"466\" border=\"0\">
");
$color1 = $info [stripe1];
$color2 = $info [stripe2];
$row_count = 0;
while( $rare = mysql_fetch_array( $get_rares ) ) {
$row_color = ($row_count % 2) ? $color1 : $color2;
?>
<td>
<td id="<?php
echo $rare ["id"];
?>" width="15%" style="text-align:center;background-color:#<?php
echo $row_color;
?>"><font face=verdana size=1><?php
echo $rare ['name'];
?></font><br>
<font face=verdana size=1><img alt=""
src="<?php
echo ("" . $info [imagepath] . "" . $rare ['image'] . "");
?>"><br><?php
$value = $rare ['value'];
$value = str_replace(".0", "", $value);
echo $value;
?> HC</font></td>
</td>
<?php
$row_count ++;
if($row_count == 6) {
echo '</tr><tr>'; //close and open a row if $row_count=;6
$row_count = 0;
}
}
echo ("</table><br>
");
}
?>
Jackboy
22-12-2008, 10:10 AM
I'm not sure that would work.
Haha i didn't know what he wanted, but i thought he had the string as OO1HC
OO20HC etc and he wanted just the 20 HC bit, in which case explode could be used.
Habtopia
22-12-2008, 11:54 AM
Jxhn you have been amazing help seriously the .0's are now filtered out :)
Habtopia
22-12-2008, 12:18 PM
i filtered 576 to 8T 8 this shows 576 as 8T 8 HC but doing this for every rare would be time consuming and id have to change them all when throne value changed, is there anyway to grab throne value then so it would change them all into T + HC?
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.