خطای mysql_fetch_array

sanecity

Member
با سلام کد منو ببینید
رو لوکال درسته ولی روی سرور گیر میده


PHP:
<?php 
//********************** show_config ***********************
function show_config($cat)
{
	connect();
	$query = "select * from site_config";
	$result = mysql_query($query); 
    $row = mysql_fetch_array($result);
	$row = trim ($row['$cat']);
	return $row ;
}
//**********************************************************

?>

بعد از اجرا خطای زیر رو میده

PHP:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/

مقداری که به تابع میره اینه
PHP:
show_config('site_active')

لطفا کمک کنید! هر کاری میکنم جواب نمیده :cry:
 

sanecity

Member
وضعیت بدتر از اونیه که فکر میکردم


در تمام برنامه این ارور هست

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/


روی لوکال درست بود
من رو سرور با phpMyAdmin دیتا بیس رو ایمپورت کردم
همه چیز درسته تیبلها ساخته شده
نمیدونم این مشکل از کجاست

لطفا کمکم کنید


:?:
 

ErfanRia

New Member
اسم دیتابیس و ستونها رو باید بین `` قرار بدی. در اینجا:

PHP:
$query = "select * from `site_config`";
 

I.NoBody

Active Member
اینو تست کن :
PHP:
<?php 
//********************** show_config ***********************
function show_config($cat)
{
    connect();
    $query = "select * from site_config";
    $result = mysql_query($query);
    if(mysql_numrows($result)<1){
     die("not data fetched");
   }
    $row = mysql_fetch_assoc($result);
    $row = trim ($row['$cat']);
    return $row ;
}
//**********************************************************

?>
 

ziXet

مدیر انجمن PHP/MYSQL
با سلام کد منو ببینید
رو لوکال درسته ولی روی سرور گیر میده


PHP:
<?php 
//********************** show_config ***********************
function show_config($cat)
{
	connect();
	$query = "select * from site_config";
	$result = mysql_query($query); 
    $row = mysql_fetch_array($result);
	$row = trim ($row['$cat']);
	return $row ;
}
//**********************************************************

?>

بعد از اجرا خطای زیر رو میده

PHP:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/

مقداری که به تابع میره اینه
PHP:
show_config('site_active')

لطفا کمک کنید! هر کاری میکنم جواب نمیده :cry:
این مشکل وقتی پیش میاد که ورژن های قدیمی تر روی سرور نصب باشه.
همونطور که erfanria گفت اگه از اون کارکتر ها استفاده کنی مشکل حل میشه
 

sanecity

Member
با تشکر

با سلام و تشکر از شما دوستان
مشکلم حل شد

:rose:

من تازه php رو شروع کردم
یه مشکل دیگه هم دارم

من واسه ساختن یه نظر سنجی یه کد پیدا کردم و یکمی دسکاری کردمش
رو لوکال چون ویندوزه همه چی درسته و تصویر ساخته میشه

ولی روی سرور لینوکس به این خط کد گیر داده و اجرا نمیشه

PHP:
putenv('GDFONTPATH=C:\WINDOWS\Fonts');

خطا :

Warning: putenv() [function.putenv]: Safe Mode warning: Cannot set environment variable 'GDFONTPATH' - it's not in the allowed list in /var/www/vhosts/

باید مسیر فونت رو چی بدم ؟

فونتمم arial است
 
آخرین ویرایش:

ziXet

مدیر انجمن PHP/MYSQL
با سلام و تشکر از شما دوستان
مشکلم حل شد

:rose:

من تازه php رو شروع کردم
یه مشکل دیگه هم دارم

من واسه ساختن یه نظر سنجی یه کد پیدا کردم و یکمی دسکاری کردمش
رو لوکال چون ویندوزه همه چی درسته و تصویر ساخته میشه

ولی روی سرور لینوکس به این خط کد گیر داده و اجرا نمیشه

PHP:
putenv('gdfontpath=c:\windows\fonts');

خطا :

warning: Putenv() [function.putenv]: Safe mode warning: Cannot set environment variable 'gdfontpath' - it's not in the allowed list in /var/www/vhosts/

باید مسیر فونت رو چی بدم ؟

فونتمم arial است
باید به صورت محلی آدرس دهی کنی.
 

I.NoBody

Active Member
با سلام و تشکر از شما دوستان
مشکلم حل شد

:rose:

من تازه php رو شروع کردم
یه مشکل دیگه هم دارم

من واسه ساختن یه نظر سنجی یه کد پیدا کردم و یکمی دسکاری کردمش
رو لوکال چون ویندوزه همه چی درسته و تصویر ساخته میشه

ولی روی سرور لینوکس به این خط کد گیر داده و اجرا نمیشه

PHP:
putenv('gdfontpath=c:\windows\fonts');

خطا :

warning: Putenv() [function.putenv]: Safe mode warning: Cannot set environment variable 'gdfontpath' - it's not in the allowed list in /var/www/vhosts/

باید مسیر فونت رو چی بدم ؟

فونتمم arial است
لطفاً بگو مشکلت چی بود و چطور حل شد.
اینجا انجمن هست و اگر قراره یک مشکلی پیش بیاد و بعدش حل شه، بقیه هم باید بتونن از اون استفاده کنن و مشکلات مشابهشون رو حل کنن
 

sanecity

Member
با تشکر
من این علامت `` رو به کدم اظافه کردم
همونی که جناب erfanria عرض کرددند

در مورد فونت کمک کنید ؟
 
آخرین ویرایش:

ziXet

مدیر انجمن PHP/MYSQL
میشه یه مثال بزنید
متوجه نشدم
چی باید بنویسم ؟
ببین من کدتو ندیدم که چجوری روی تصویر مینویسه از تابع imagettftext استفاده میکنه یا نه؟

اگه میشه کد مربوط به قسمت نوشتن رو بذار
 

sanecity

Member
اینم کدم

PHP:
<?php
/*******************************************
  Database query to get poll info 
*******************************************/
connect();

$query = "select * from site_poll order by poll_number DESC"; 
$result = mysql_query($query);
$num_candidates = mysql_num_rows($result); 

// calculate total number of votes so far
$total_votes=0;
while ($row = mysql_fetch_array($result)) 
{
    $total_votes +=  $row ['poll_number'];
}
@mysql_data_seek($result, 0);  // reset result pointer


/*******************************************
  Initial calculations for graph 
*******************************************/
// set up constants
putenv('GDFONTPATH=');
$width=400;        // width of image in pixels - this will fit in 640x480
$left_margin = -30; // space to leave on left of graph
$right_margin= 80; // ditto right   
$bar_height = 15;  
$bar_spacing = 10; 
$font = 'arial.ttf';
$title_size= 14; // point
$main_size= 9; // point
$darsad_size= 8; // point
$small_size= 9; // point
$text_indent = 10; // position for text labels from edge of image

// set up initial point to draw from
$x = $left_margin + 60;  // place to draw baseline of the graph
$y = 50;		  // ditto 
$bar_unit = ($width-($x+$right_margin)) / 100;   // one "point" on the graph

// calculate height of graph - bars plus gaps plus some margin
$height = $num_candidates * ($bar_height + $bar_spacing) + 50;   

/*******************************************
  Set up base image 
*******************************************/
// create a blank canvas
$im = ImageCreateTrueColor($width,$height);   
     
// Allocate colors   
$white=ImageColorAllocate($im,255,255,255);   
$blue=ImageColorAllocate($im,150,150,150);   
$black=ImageColorAllocate($im,0,0,0);   
$cry=ImageColorAllocate($im,200,200,200);  
$pink = ImageColorAllocate($im,0,128,128); 
$yellow = ImageColorAllocate($im,244,0,0); 
$text_color = $black;
$percent_color = $white;
$percent_color2 = $black;
$bg_color = $white;
$line_color = $cry;
$bar_color = $blue;
$number_color = $pink;

// Create "canvas" to draw on 
ImageFilledRectangle($im,0,0,$width,$height,$bg_color);   

// Draw outline around canvas 
ImageRectangle($im,0,0,$width-1,$height-1,$line_color);   

// Add title
$title = 'Poll Results';
$title_dimensions = ImageTTFBBox($title_size, 0, $font, $title);
$title_length = $title_dimensions[2] - $title_dimensions[0];
$title_height = abs($title_dimensions[7] - $title_dimensions[1]);
$title_above_line = abs($title_dimensions[7]);
$title_x = ($width-$title_length)/2;  // center it in x 
$title_y = ($y - $title_height)/2 + $title_above_line; // center in y gap
ImageTTFText($im, $title_size, 0, $title_x, $title_y, 
             $text_color, $font, $title);  

// Draw a base line from a little above first bar location 
// to a little below last  
ImageLine($im, $x, $y-2, $x, $height-15, $line_color);   

/*******************************************
  Draw data into graph 
*******************************************/
// Get each line of db data and draw corresponding bars  
$si = 1 ; 

while ($row = mysql_fetch_array ($result)) 
{
  if ($total_votes > 0)
    $percent = intval(round(($row ['poll_number'] / $total_votes )*100));
  else 
    $percent = 0;

  // display percent for this value  
  $percent_dimensions = ImageTTFBBox($main_size, 0, $font, $percent. ' % ');
  $percent_length = $percent_dimensions[2] - $percent_dimensions[0];
   
  
  if ($total_votes > 0)
    $right_value = intval(round(($row ['poll_number']/$total_votes)*100));
  else
    $right_value = 0;

  // length of bar for this value   
  $bar_length = $x + ($right_value * $bar_unit);   

  // draw bar for this value   
  ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);   

  // draw title for this value   
  ImageTTFText($im, $main_size, 0, $text_indent, $y+($bar_height/1.5), 
               $text_color, $font, $si);  

  // draw outline showing 100% 
  ImageRectangle($im, $bar_length+1, $y-2, 
                ($x+(100*$bar_unit)), $y+$bar_height, $line_color);   

  // display numbers   
  ImageTTFText($im, $small_size, 0, $x+(100*$bar_unit)+20, $y+($bar_height/1.5),
               $number_color, $font, $row ['poll_number'] .' - '.$total_votes);
			   
	//*********************************************		 
			  if ($percent <= 93)
			   {
			  ImageTTFText($im, $darsad_size, 0, $width-$percent_length-80, 
               $y+($bar_height/1.5), $percent_color2, $font, $percent .' % ');
			   }
			   if ($percent >= 90 )
			   {
			    ImageTTFText($im, $darsad_size, 0, $width-$percent_length-80, 
               $y+($bar_height/1.5), $percent_color, $font, $percent.' % ');
			   
			  }

  // move down to next bar
  $y=$y+($bar_height+$bar_spacing);  
  
  $si++ ; 
}   

/*******************************************
  Display image 
*******************************************/

Imagejpeg($im,"style/images/poll.jpg",100);   

/*******************************************
  Clean up 
*******************************************/
ImageDestroy($im);   
?>
 

ziXet

مدیر انجمن PHP/MYSQL
اینم کدم

PHP:
<?php
/*******************************************
  Database query to get poll info 
*******************************************/
connect();

$query = "select * from site_poll order by poll_number DESC"; 
$result = mysql_query($query);
$num_candidates = mysql_num_rows($result); 

// calculate total number of votes so far
$total_votes=0;
while ($row = mysql_fetch_array($result)) 
{
    $total_votes +=  $row ['poll_number'];
}
@mysql_data_seek($result, 0);  // reset result pointer


/*******************************************
  Initial calculations for graph 
*******************************************/
// set up constants
putenv('GDFONTPATH=');
$width=400;        // width of image in pixels - this will fit in 640x480
$left_margin = -30; // space to leave on left of graph
$right_margin= 80; // ditto right   
$bar_height = 15;  
$bar_spacing = 10; 
$font = 'arial.ttf';
$title_size= 14; // point
$main_size= 9; // point
$darsad_size= 8; // point
$small_size= 9; // point
$text_indent = 10; // position for text labels from edge of image

// set up initial point to draw from
$x = $left_margin + 60;  // place to draw baseline of the graph
$y = 50;          // ditto 
$bar_unit = ($width-($x+$right_margin)) / 100;   // one "point" on the graph

// calculate height of graph - bars plus gaps plus some margin
$height = $num_candidates * ($bar_height + $bar_spacing) + 50;   

/*******************************************
  Set up base image 
*******************************************/
// create a blank canvas
$im = ImageCreateTrueColor($width,$height);   
     
// Allocate colors   
$white=ImageColorAllocate($im,255,255,255);   
$blue=ImageColorAllocate($im,150,150,150);   
$black=ImageColorAllocate($im,0,0,0);   
$cry=ImageColorAllocate($im,200,200,200);  
$pink = ImageColorAllocate($im,0,128,128); 
$yellow = ImageColorAllocate($im,244,0,0); 
$text_color = $black;
$percent_color = $white;
$percent_color2 = $black;
$bg_color = $white;
$line_color = $cry;
$bar_color = $blue;
$number_color = $pink;

// Create "canvas" to draw on 
ImageFilledRectangle($im,0,0,$width,$height,$bg_color);   

// Draw outline around canvas 
ImageRectangle($im,0,0,$width-1,$height-1,$line_color);   

// Add title
$title = 'Poll Results';
$title_dimensions = ImageTTFBBox($title_size, 0, $font, $title);
$title_length = $title_dimensions[2] - $title_dimensions[0];
$title_height = abs($title_dimensions[7] - $title_dimensions[1]);
$title_above_line = abs($title_dimensions[7]);
$title_x = ($width-$title_length)/2;  // center it in x 
$title_y = ($y - $title_height)/2 + $title_above_line; // center in y gap
ImageTTFText($im, $title_size, 0, $title_x, $title_y, 
             $text_color, $font, $title);  

// Draw a base line from a little above first bar location 
// to a little below last  
ImageLine($im, $x, $y-2, $x, $height-15, $line_color);   

/*******************************************
  Draw data into graph 
*******************************************/
// Get each line of db data and draw corresponding bars  
$si = 1 ; 

while ($row = mysql_fetch_array ($result)) 
{
  if ($total_votes > 0)
    $percent = intval(round(($row ['poll_number'] / $total_votes )*100));
  else 
    $percent = 0;

  // display percent for this value  
  $percent_dimensions = ImageTTFBBox($main_size, 0, $font, $percent. ' % ');
  $percent_length = $percent_dimensions[2] - $percent_dimensions[0];
   
  
  if ($total_votes > 0)
    $right_value = intval(round(($row ['poll_number']/$total_votes)*100));
  else
    $right_value = 0;

  // length of bar for this value   
  $bar_length = $x + ($right_value * $bar_unit);   

  // draw bar for this value   
  ImageFilledRectangle($im, $x, $y-2, $bar_length, $y+$bar_height, $bar_color);   

  // draw title for this value   
  ImageTTFText($im, $main_size, 0, $text_indent, $y+($bar_height/1.5), 
               $text_color, $font, $si);  

  // draw outline showing 100% 
  ImageRectangle($im, $bar_length+1, $y-2, 
                ($x+(100*$bar_unit)), $y+$bar_height, $line_color);   

  // display numbers   
  ImageTTFText($im, $small_size, 0, $x+(100*$bar_unit)+20, $y+($bar_height/1.5),
               $number_color, $font, $row ['poll_number'] .' - '.$total_votes);
               
    //*********************************************         
              if ($percent <= 93)
               {
              ImageTTFText($im, $darsad_size, 0, $width-$percent_length-80, 
               $y+($bar_height/1.5), $percent_color2, $font, $percent .' % ');
               }
               if ($percent >= 90 )
               {
                ImageTTFText($im, $darsad_size, 0, $width-$percent_length-80, 
               $y+($bar_height/1.5), $percent_color, $font, $percent.' % ');
               
              }

  // move down to next bar
  $y=$y+($bar_height+$bar_spacing);  
  
  $si++ ; 
}   

/*******************************************
  Display image 
*******************************************/

Imagejpeg($im,"style/images/poll.jpg",100);   

/*******************************************
  Clean up 
*******************************************/
ImageDestroy($im);   
?>
اوکی فهمیدم.
آدرس دهی محلی به این صورت هست که پوشه ای که فایل در اون اجرا میشه، میشه ریشه و بعدش آدرس دهی ها بر اساس اون انجام میشه.
شما فایل فونت مورد نظر رو تو پوشه font بذار و پوشه فونت رو کنار همین فایل php بذار.
و بعد خط 30 رو اینجوری تغییر بده:
PHP:
$font = 'font/arial.ttf';
و خط 24 رو هم پاک کن.

موفق باشید
 

sanecity

Member
با سلام و تشکر از شما به گفته شما عمل کردم
ولی این ارور رو داد
Unable to access fonts/arial.ttf in /var/www/vhosts

دسترسی رو 777 کردم
بازم نشد

فونت رو کنار فایل ریختم
بازم نشد

از فونت دیگه استفاده کردن
بازم نشد

دیگه موندم چیکار کنم
:-?
 

ziXet

مدیر انجمن PHP/MYSQL
با سلام و تشکر از شما به گفته شما عمل کردم
ولی این ارور رو داد
Unable to access fonts/arial.ttf in /var/www/vhosts

دسترسی رو 777 کردم
بازم نشد

فونت رو کنار فایل ریختم
بازم نشد

از فونت دیگه استفاده کردن
بازم نشد

دیگه موندم چیکار کنم
:-?
font نه fonts
 

sanecity

Member
با سلام
هم پوشه font گذاشتم و هم fonts
فرقی نداره
دسترسی رو 777 کردم
بازم

Unable to access font/arial.ttf
 

sanecity

Member
میگم این تاپیک محتواش با عنوانش نمیخونه
لطفا یکی از مدیران یه عنوان درست واسه این تاپیک انتخاب کنه
با تشکر:rose:
 

ziXet

مدیر انجمن PHP/MYSQL
با سلام
هم پوشه font گذاشتم و هم fonts
فرقی نداره
دسترسی رو 777 کردم
بازم

Unable to access font/arial.ttf
سلام

ببین این کد زیر رو تو یه فایل دیگه بریز و اجرا کن:
PHP:
<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
فونت arial.ttf رو دقیقا کنارش بذار.
اجرا کن ببین کار میکنه؟
 

sanecity

Member
کدی که شما دادی درست کار میکنه!
عجیبه ! کنار همون فایل خودم ریختم یعنی دایرکتوری و فونت مورد استفاده یکیه
ولی فایل منو این ارور رو میده
Unable to access font/arial.ttf

سطح دسترسی فایلها هم یکیه؟!
به نظرتون مشکل از کجا میتونه باشم

بهتر نیست کدمو عوض کنم؟
چی کار کنم
 

sanecity

Member
یه اتفاق عجیب افتاد

:D

من به فونت دسترسی 777 دادم همه چی درست شد!!!!
واقعا از شما ممنونم :rose:
راستی این دسترسی ها میتونه خطرناک باشه؟
 

جدیدترین ارسال ها

بالا