Jump to content

Mysql results help


blukkie

Recommended Posts

Hi,

 

I'm not that good at PHP but I'm trying to make a small script that gets its information out of our Database. There is one important detail not working though.

 

I'm trying to get a name out of the Database but all I get is this error: "Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 7 in C:\wamp\www\ticket.php  on line 34".

When I execute the query in my DB, it returns a value. But here it seems to not return anything. I have checked, and $guid does get a value stored.

 

Is there something wrong with my script or could it be something else I'm not aware of?

 

<?php

$realmd = array(
'db_host'=> 'host', //ip of db realm
'db_username' => 'name',//realm user
'db_password' => 'pw',//realm password
'db_name'=> 'db',//character db name
);

/*Connect and Select*/
$realmd_bc_new_connect = mysql_connect($realmd['db_host'],$realmd['db_username'],$realmd['db_password']) or die("Problem connecting to MySQL<br>" . mysql_error());
$selectdb = mysql_select_db($realmd['db_name'],$realmd_bc_new_connect) or die("Problem selecting the database<br>" . mysql_error());
if (!$realmd_bc_new_connect || !$selectdb){
echo "Could not connect to db.";
die;
}

$action = array();
$action = mysql_query("SELECT * FROM `character_ticket`");
$action_rows = mysql_num_rows($action);

for ($i = 1; $i != $action_rows; ++$i)
{
$ticketid = mysql_query("SELECT `ticket_id` FROM character_ticket WHERE ticket_id = '$i'");
$guid = mysql_query("SELECT `guid` FROM character_ticket WHERE ticket_id = '$i'");
$getname = mysql_query("SELECT name FROM characters WHERE guid = '$guid'");
$tickettext = mysql_query("SELECT `ticket_text` FROM character_ticket WHERE ticket_id = '$i'");
$ticketchange = mysql_query("SELECT `ticket_lastchange` FROM character_ticket WHERE ticket_id = '$i'");

echo "<b>TICKET #</b>";
echo mysql_result($ticketid,0); echo ":</br>";
echo "<b>PLAYER: </b>";
echo mysql_result($guid,0); echo "</br>";
//echo mysql_result($getname,0); echo "<br>";
echo "<b>MADE: </b>";
echo mysql_result($ticketchange,0); echo "</br>";
echo "<b>TICKET: </b></br>";
echo mysql_result($tickettext,0); echo "</br></br>";
}
?>

 

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/201895-mysql-results-help/
Share on other sites

Try this

<?php

$realmd = array(
'db_host'=> 'host', //ip of db realm
'db_username' => 'name',//realm user
'db_password' => 'pw',//realm password
'db_name'=> 'db',//character db name
);

/*Connect and Select*/
$realmd_bc_new_connect = mysql_connect($realmd['db_host'],$realmd['db_username'],$realmd['db_password']) or die("Problem connecting to MySQL<br>" . mysql_error());
$selectdb = mysql_select_db($realmd['db_name'],$realmd_bc_new_connect) or die("Problem selecting the database<br>" . mysql_error());
if (!$realmd_bc_new_connect || !$selectdb){
echo "Could not connect to db.";
die;
}

$action = array();
$action = mysql_query("SELECT * FROM `character_ticket`");
$action_rows = mysql_num_rows($action);

for ($i = 1; $i != $action_rows; ++$i)
{
   $result = mysql_query("SELECT `ticket_id`* FROM character_ticket WHERE ticket_id = '$i'");
   $row = mysql_fetch_assoc($result);
   
   echo "<b>TICKET #</b>";
   echo $row['ticket_id'].":</br>";
   echo "<b>PLAYER: </b>";
   echo $row['guid']."</br>";
   echo "<b>MADE: </b>";
   echo $row['ticket_lastchange']."</br>";
   echo "<b>TICKET: </b></br>";
   echo $row['ticket_text']."</br>";
}
?>

Note that I removed the $name = ... line in the loop, since it wasn't being used. Also, you don't need to create a query for each individual item in a row. That will cause you all sorts of problems when you get multiple users doing the same queries, and will cause crashing no doubt

Link to comment
https://forums.phpfreaks.com/topic/201895-mysql-results-help/#findComment-1058935
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.