Forum Moderators: coopster

Message Too Old, No Replies

using mysql instead of input GET in php code.

         

Dreap

2:10 pm on Mar 28, 2010 (gmt 0)

10+ Year Member



 $monitor = GameQuery::Monitor(
$_GET['gq_protocol'],
$_GET['gq_hostname'],
$options
);


I want to take gq_hostname from database instead of input form, what code should I use?

I tried following but doesn't seem to work


include('db_config.php');
mysql_connect("$dbhostname", "$dbusername", "$dbpassword") or die(mysql_error()); mysql_select_db("$dbname") or die(mysql_error());

$query = "SELECT * FROM main_table WHERE id = '1'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
$string = $row['gq_hostname'];

$monitor = GameQuery::Monitor(
$_GET['gq_protocol'],
$row['gq_hostname'],
$options
);

eelixduppy

2:40 pm on Mar 28, 2010 (gmt 0)



What are the errors that you are getting when you run this? What isn't working?

Matthew1980

2:55 pm on Mar 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Dreap,

I suspect that one error would be a: "failed to connect error" as there is no connection reference in the mysql_select_db($dbname); function. Also as there is no handle on the mysql_connect, there would never be a valid reference for subsequent queries:-

$conn = mysql_connect($dbhostname, $dbusername, $dbpassword) or die(mysql_error());
mysql_select_db($dbname, $conn) or die(mysql_error());


Retrieval of data:-

$query = "SELECT * FROM `main_table` WHERE `id` = '1'";
$result = mysql_query($query, $conn) or die(mysql_error());
while($row = mysql_fetch_array($result)) {//start brace
$string = $row['gq_hostname'];
}//There wasn't an end brace?


This will just get everything from the database that is associated with the ID of 1, so i assume as this will retrieve what your after ;-p

Your function:-

$monitor = GameQuery::Monitor(
$_GET['gq_protocol'],
$row['gq_hostname'],
$options
);


Is the $_GET['gq_protocol']; actually set in the URL at this point in the code, if not, nothing will be populated at this point, so firstly check to see if this var isset & holds a value... Just a suggestion ;-p

Also, highly recommended for dev work but not for release: or die(mysql_error()); when you go public remove that function from the above code, as this could provide hackers with information on your table/database structures ;-p

Yes, as eelixduppy asks, what are the error's that you get?

Cheers,
MRb

Dreap

8:50 pm on Mar 28, 2010 (gmt 0)

10+ Year Member



Was totally my mistake, forgot bracet :D

Need help with this one tho.



$options = array(
'background' => '#ffffff',
'foreground' => '#000000',
'color_online' => '#00ff00',
'color_offline' => '#ff0000',
);

if($query_success == false) {
echo <<<TEMPLATEHTML
<div style="background-color: {$options['background']}; color: {$options['foreground']}">
<span style="background-color: {$options['color_offline']}; border: 1px solid {$options['foreground']}; font-weight: bold">&nbsp;&nbsp;&nbsp;&nbsp;</span>
<b>SERVER OFFLINE</b>
</div>
TEMPLATEHTML;
}

else {
echo <<<TEMPLATEHTML
<div style="background-color: {$options['background']}; color: {$options['foreground']}">
<span style="background-color: {$options['color_online']}; border: 1px solid {$options['foreground']}; font-weight: bold">&nbsp;&nbsp;&nbsp;&nbsp;</span>
</div>
<b>SERVER ONLINE</b>
TEMPLATEHTML;
}


I want to use linked URLs instead of plain color but can't figure how to make it show images instead of color.

Matthew1980

9:06 pm on Mar 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Dreap,

Good that you fixed the original query ;-p

As for this one, if you are wanting to use images (though css) instead of just plain background color, then the background needs to have another attribute attached to it ie:-

URL("path/to/image/that/you/want.jpg");

for example, this sets the background color & the image on top of it:-

background: #FFFFF url('path/to/image/yourimage.jpg');

At least that's what I think as you mean ;-p

Cheers,
MRb