Jump to content

Xyn1407

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Xyn1407's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I recently created a site that creates charts with google charts api and information it collects from a database that the owner of the site inputs. All works well except for the left and right axis top numbers. These display odd top numbers and I am wondering what it would take to get it to round the number up to the nearest 100 so that it displays evenly. I set the code to go 100 over and I think that somewhere in here is my problem. If a user inputs a number of 255 and that number is the highest within the chart data then the top number displays 355. It displays both top number 255 and 355. Now what this does is makes the gains look higher that they actually are because it goes from 200, 255 and then 355. Please see example out put here I am sure there must be away to dynamically add the axis labels without it pulling in the info from the data itself right? I have asked this very same question on google code and still know answer. Here is an example of the code I am using. <?php $id_entity = $_product->getId(); $chart_num_rows = 0; $db_obj = mysql_connect('localhost', 'XXX', 'XXX'); mysql_select_db('XXXX', $db_obj); $query = " SELECT a.frontend_label AS frontend_label, b.value AS value FROM XXX AS a, XXX AS b WHERE a.attribute_id = b.attribute_id && b.entity_id = ".$id_entity." && a.attribute_id BETWEEN 564 AND 568 ORDER BY a.attribute_id ASC "; $result = mysql_query($query); if(mysql_num_rows($result) != 0) { @$chart_num_rows = mysql_num_rows($result); } if($chart_num_rows != 0) { $max = 0; $min = 0; $array = array(); for($i = 0; $i < $chart_num_rows; $i++) { $row = mysql_fetch_object($result); $clean = str_replace(" ", '', $row->value); $explode = explode(',', $clean); if($i == 4) { $min = min($explode); $max = max($explode); } else { if($min < min($explode)) { $min = min($explode); } if($max < max($explode)) { $min = max($explode); } } $array[$i][0] = $row->frontend_label; /* Labels */ $array[$i][1] = $clean; /* Line Data */ $array[$i][2] = str_replace(',', '|', $clean); /* Labels */ } $count = 100; $left_right = ''; while($count < $max) { $left_right .= $count.'|'; $count = ($count + 100); } $left_right .= $max.'|'.($max + 100); $output = '<img src="http://chart.apis.google.com/chart? cht=lc&chd=t:'.$array[1][1].'|'.$array[2][1].'|'.$array[3][1].'|'. $array[4][1]; $output .= '&chls=3|3|3|3|3|3,6,3&chf=bg,s,FFFFFF&chxl=0:|'.$array[0] [2].'|1:|'.$left_right.'|2:|'.$left_right; $output .= '&chs=575x300&chf=bg,s,FFFFFF&chco=444444,444444,0000FF, 0000FF&chxt=x,y,r&chds=50,'.($max + 100); $output .= '&chm=h,76A4FB,0,0:1:.2,2,-1|V,76A4FB,0,::2,0.5,-1"><br / ><br />'; } else { $output = 'There are no current statistics available for this chart.'; } echo $output; ?>
  2. Hello I have a project where there is data pulled in to a google image chart from a mysql database. The query is showing all the data that is supposed to be pulled in but the graph shows a straight line and is not showing all the data in the url from the query which you can see under url code. This is the url that is posted after the query here Here is the code that I am using to generate the chart <? $id_entity = $_product->getId(); $db_obj = mysql_connect('localhost', 'XXX', 'XXX'); mysql_select_db('data_base', $db_obj); $query = " SELECT a.frontend_label AS frontend_label, b.value AS value FROM eav_attribute AS a, catalog_product_entity_varchar AS b WHERE a.attribute_id = b.attribute_id && b.entity_id = ".$id_entity." && a.attribute_id BETWEEN 564 AND 568 ORDER BY b.attribute_id ASC "; $result = mysql_query($query); $num_rows = mysql_num_rows($result); $array = array(); $max = array(); for($i = 0; $i < $num_rows; $i++) { $row = mysql_fetch_object($result); $clean = str_replace(" ", '', $row->value); $explode = explode(',', $clean); $max[$i] = max($explode); $array[$i][0] = $row->frontend_label; $array[$i][1] = $clean; $array[$i][2] = str_replace(',', '|', $clean); } print_r($array); ?> <img src="http://chart.apis.google.com/chart?cht=lc&chd=t:<?php echo $array[1][1]; ?>&chf=bg,s,FFFFFF&chxl=0:|<?php echo $array[0][2];?>|1:|<?php echo $array[1][2];?>|2:|<?php echo $array[2][2];?>&chs=500x250&chf=bg,s,FFFFFF&chco=FF0000&chxt=x,y,r"> Here is the array that is printed by the above code Array ( [0] => Array ( [0] => RPM [1] => 2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000 [2] => 2000|2500|3000|3500|4000|4500|5000|5500|6000|6500|7000 ) [1] => Array ( [0] => Torque Before Tuning [1] => 200,300,315,320,400,500,400,390,370,360,350 [2] => 200|300|315|320|400|500|400|390|370|360|350 ) [2] => Array ( [0] => Horsepower Before Tuning [1] => 250,300,310,350,370,380,370,350,330,300,290 [2] => 250|300|310|350|370|380|370|350|330|300|290 ) [3] => Array ( [0] => Torque After Tuning [1] => 275,305,317,360,380,383,373,360,340,320,300 [2] => 275|305|317|360|380|383|373|360|340|320|300 ) [4] => Array ( [0] => Horsepower After Tuning [1] => 300,350,370,400,450,470,500,470,450,420,390 [2] => 300|350|370|400|450|470|500|470|450|420|390 ) ) Here is the url that is produced. http://chart.apis.google.com/chart?cht=lc&chd=t:200,300,315,320,400,500,400,390,370,360,350&chf=bg,s,FFFFFF&chxl=0:|2000|2500|3000|3500|4000|4500|5000|5500|6000|6500|7000|1:|200|300|315|320|400|500|400|390|370|360|350|2:|250|300|310|350|370|380|370|350|330|300|290&chs=500x250&chf=bg,s,FFFFFF&chco=FF0000&chxt=x,y,r I have been beating my head on my keyboard for days trying to figure out where I went wrong. Figured another set of eyes might help.
  3. I am trying to add a View Comment and Add Comment link under a picture/ rate type blog that I am helping a friend with and my php skills have taken me as far as I can get (nowhere) I want the links underneath the pictures to go to a leave comment link and a view comment link. There are multiple picture on one page with the next/previous navigation. Everything else works great. For some reason I just get the index.php?i=$image_id which $image_id should be the id of the picture. Any help on this would be appreciated. Thanks. Here is the code of the index.php page. <? require ( "header.php" ); ?> <?php $config = './admin/config.php'; if( file_exists( $config ) ) { if( is_readable( $config ) ) { require( $config ); } else { die( "Cannot read config file" ); } } else { die( "Cannot find config file" ); } ///////////////////////////////////////// ////// Prevent Injection Attack ///////// ///////////////////////////////////////// if(isset($_GET['pageno'])) { if(!is_numeric($_GET['pageno'])) { return 'Error: '.$_GET['pageno']; exit(); } $pageno = $_GET['pageno']; } else { $pageno=1; } ///////////////////////////////////////// /////////// PAGES FUNCTION ////////////// ///////////////////////////////////////// function pages($tablename, $pageno, $perPage, $query) { $output = ''; $queryCount = 'SELECT count(*) FROM ds_images ORDER BY image_id'; $resultCount = mysql_query($queryCount); $fetch_row = mysql_fetch_row($resultCount); $numrows = $fetch_row[0]; // Get the comments //$queryCount = 'SELECT count(*) FROM ds_comments ORDER BY comment_id' $allImages = getTemplate( 'allImages' ); eval( "\$allImages = \"$allImages\";" ); $user_login = getUserLogin( $user_id, true, ' class="header"' ); $imageAltText = getImageName( $image_id, true ); $size = imageSize( $image_id ); $imageHeightWidth = $size[ 1 ]; require( "$GLOBALS[LIB_PATH]/include/profileBar.php" ); // if there is no results if($numrows == 0) { return 'Query returned 0 results.'; exit(); } $lastpage = ceil($numrows/$perPage); $pageno = (int)$pageno; if($pageno<1) { $pageno=1; } elseif($pageno>$lastpage) { $pageno=$lastpage; } // ----- PAGE LINKS ----- if($pageno==1) { $pages .= 'FIRST | PREVIOUS '; } else { $pages .= "<a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> | "; $prevpage=$pageno-1; $pages .= " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREVIOUS</a> "; } $pages .= ' ( Page '.$pageno.' of '.$lastpage.' ) '; if($pageno==$lastpage) { $pages .= ' NEXT | LAST '; } else { $nextpage = $pageno+1; $pages .= " <a href='".$_SERVER['PHP_SELF']."?pageno=$nextpage'>NEXT</a> | "; $pages .= " <a href='".$_SERVER['PHP_SELF']."?pageno=$lastpage'>LAST</a>"; } $limit=' LIMIT '.($pageno-1)*$perPage.', '.$perPage; $query = $query.$limit; $result = mysql_query($query); if(!$result) { return 'Query failed: '.mysql_error(); } while($row = mysql_fetch_object($result)) echo "<div align=center>"."<img src=\"image.php?i=$row->image_id\"/>".'<br /> "<div style=width:45%; align=right>"<a align=right href="imageComments.php?i=$image_id">View Commments</a><br /><div style=width:45%; align=right>"<a align=right href="leaveComment.php?i=$image_id">Leave Comment</a><br /><br />'."</div></div></div>"; { // $output = //$output .= $row['image_id'].' '.$row['image'].'<br />'; // $output = //$output .= $row['comment_id'].' '.$row['comment'].'<br />'; } $output .= '<div style="width:100%; text-align:center; font-size:smaller; color:#fff;">'.$pages.'</div>'; //$output .= 'Total number of products: '.$numrows; return $output; exit(); } ///////////////////////////////////////// ////////// Set paramenters ////////////// ///////////////////////////////////////// $tablename = 'ds_images';//.// 'ds_comments'; $perPage = 10; $query = 'SELECT * FROM ds_images ORDER BY image_id DESC'; //$query = 'SELECT * FROM ds_comments ORDER BY comment_id DESC'; echo pages($tablename, $pageno, $perPage, $query); ?> <?php //require( "$GLOBALS[LIB_PATH]/include/profileBar.php" ); //$rateBarColor = $styleArray[ 1 ]; //$rateBar = getTemplate( 'rateBar' ); //eval( "\$rateBar = \"$rateBar\";" ); $commentsCount = getCommentsCount( $image_id ); require( "$GLOBALS[LIB_PATH]/include/lastFew.php" ); $userExtraFields = getExtraFieldsDisplay( $GLOBALS[ 'TB_USERS' ], $image_id ); $imageExtraFields = getExtraFieldsDisplay( $GLOBALS[ 'TB_IMAGES' ], $image_id ); //$index = getTemplate( 'index' ); //eval( "\$index = \"$index\";" ); //$FinalHTML .= $index; require( "$GLOBALS[LIB_PATH]/include/footer.php" ); echo cleanFinalOutput( $FinalHTML ); ?>
×
×
  • 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.