Jump to content

masgas

Members
  • Posts

    64
  • Joined

  • Last visited

    Never

Everything posted by masgas

  1. really good idea!! now I will think which is the best option to keep the array and give it a try! you've been of great help! thank you very much!
  2. great! now the question is: wouldn't the array be again= $array = ('one', 'two', 'three', 'four'); next time I load the page? how could I keep it: Array { [0] => two [1] => three [2] => four [3] => newvalue }
  3. Hi thank you for your reply! I think that's exactly what I need... I will read about the array_splice function and try to get the solution... the idea is having an array of four values all the time, insert one in the end and delete the first one... alway pulling the values from a db...
  4. Hi all! I'm trying to do something and I don't get it right... The idea is to have a first array with 4 different values, and each time the user clicks a form button: connect with the db, select one new value, delete the first from the existing array and insert the new value in the array... I've tried this code but no good result //connect with DB //pull new value results in => $tipoAvo = $row['tipoAvo']; /*Pre declared array $avos[0]="A320"; $avos[1]="B739"; $avos[2]="A319"; $avos[3]="B737"; Pre declared array */ //code $sum=sizeof($avos); if($sum<=4){ array_push($avos, $tipoAvo); reset($avos); $firstinarray = current($avos); $avos=array_diff($avos, array($firstinarray)); while (list($index, $values)= each ($avos)){ echo "<br>".$index." - ".$values;} } but it prints the same array, only inserting in the last line the new value: $tipoAvo. I guess that having the array predeclared is producing this result... but I don't get any ideas of how to avoid this... I would like to add it and delete the first, and so on each time the user cliks the form... so I have a 4 valued array that changes constantly... Thank you for your help, and ideas...
  5. ok... that worked just fine! thank you
  6. Hi this is what it echoes! SELECT RED FROM users WHERE nick = 'LEVC'SELECT GREEN FROM users WHERE nick = 'LEVC'SELECT BLUE FROM users WHERE nick = 'LEVC'SELECT BROWN FROM users WHERE nick = 'LEVC'
  7. I have this code. I get the message: Parse error: syntax error, unexpected T_STRING in /home/..../test.php on line 7 any ideas why??? $con = mysql_connect ('','','') or die ("no con"); @mysql_select_db ('$db_name') or die ('error DB'); $col = array('1'=>RED, '2'=>GREEN, '3'=>BLUE, '4'=>BROWN); foreach ($col as $key => $value){ $sql= "SELECT $value FROM users WHERE nick = '$_SESSION[nick]'"; $res= mysql_query($sql) or die mysql_errno($sql); while ($row=mysql_fetch_assoc($res)){ if ($row[$valor]!=''){$var= $row[$valor];} echo $var; } } ?>
  8. you see, this script is within a "paging text"... the variables I'm receiving the text is $string... I tried to use explode (); but I didn't manage to get it to work either...
  9. I use dreamweaver MX 2004 and it works great with apache and mysql... I go to the menu: site - manage sites - new site - and in the "local root folder" I have "C:\xampp\htdocs\" cause I'm working with xampp... this makes it work just fine with me...
  10. hi people! I have this function which prints an X numbers of characters, but I can't manage to make it not cut words in half... this is the last I tried and it prints the $maxlength=880 but the rest it doesn't print them... what am I doing wrong??? function substring($string, $start, $maxlength){ $strlength = strlen($string); $trows = ceil($strlength / $maxlength); for($i=0; $i<$trows; $i++){ $line = substr($string, $start, $maxlength); $lineB = substr($line, $start, strrpos($line, ' ')); } return $lineB; } thanks for your time!
  11. [color=orange]//This code selects an article from a DB and prints 250 chars at a time[/color] <?php $host="l"; // Host name $username=""; // Mysql username $password=""; // Mysql password $db_name=""; // Database name $tbl_name=""; // Table name /*********** Start function *********************/ function substring($string, $start, $maxlength){ $strlength = strlen($string); // divide the length by the limit $trows = ceil($strlength / $maxlength); for($i=0; $i<$trows; $i++){ $lineB = substr($string, $start, $maxlength).""; $lineA = explode (" ", $lineB, 60); array_pop($lineA); $line = implode (" ", $lineA); } return $line; } /************** End Function ******************/ $maxlength = 250; if (!isset($_GET['page'])){   $page = 1;   $start = 0;   } else {   $page = $_GET['page'];   $start = ($page * $maxlength) - $maxlength;   } echo "<table width='300' height='455'>" ; mysql_connect("$host", "$username", "$password")or die("no conn DB"); mysql_select_db("$db_name")or die("no DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 1"; $result=mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) {     $id = $row["id"];     $string = $row["detail"];   echo "<tr><td>".substring($string, $start, $maxlength)."...</td></tr>"; } echo "</table>"; ?> <?php $stringlength = strlen($string); echo "<p align=center>"; // Sets link for previous 25 and return to page 1     if($page != 1){         $pageprev = ($page - 1);         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=1\">primera</a>&nbsp;&nbsp;";         echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".$pageprev."\">previa</a>&nbsp;&nbsp;&nbsp;";     }else{         echo "&nbsp;&nbsp;&nbsp;";     } // Find out the total number of pages depending on the limit set $numofpages = ($stringlength / $maxlength); $totalpages = round($numofpages); // Loop thru all the pages and echo out the links     for($i = 1; $i <= $numofpages; $i++){         if($i == $page){             echo $i." ";         }else{             echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a> ";         }     } // Check for straglers after the limit blocks     if(($stringlength % $maxlength) != 0){         if($i == $page){             echo $i." ";         }else{             echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".$i."\">".$i."</a> ";         }     } // Print out the Next 25 and Goto Last page links     if(($stringlength - ($maxlength * $page)) > 0){         $pagenext = ++$page;           echo "&nbsp;&nbsp;&nbsp;<a href=\"".$_SERVER['PHP_SELF']."?page=".$pagenext."\">siguiente</a>&nbsp;&nbsp;&nbsp;";           echo "<a href=\"".$_SERVER['PHP_SELF']."?page=".$totalpages."\">última</a>&nbsp;&nbsp;";     }else{         echo("&nbsp;&nbsp;&nbsp;");     } echo "</p>"; mysql_close(); ?>
  12. that did the trick!!!! only the next link is not working correctly! but the job was to get it printing right! I'll try to fix this next link and then post the full code for the rest of begginers like me... yo never know, someone may need something like this THANK YOU ALL
  13. aha! something like that! I've got a table with links on one side, and when I click on that link an article appears on the iframe... but this articles can have up to 20 paragraphs which is a lot for a 300 by 400 pixel box.. so the idea is page the text in the box... does it help?
  14. I'll explain myself a little better... I have a text, let's say 600 chars, and I want to page it because is too long for the space in te iframe I'm using... so I'd like to page the text... when I use the script from your last post it prints the whole message... how could I limit the text to 250 chars for example? thank you very much for your help
  15. any ideas, I'm lost right now!????
  16. I got this code now... but I can't get it to print a regular interval of text, it keeps on adding 25 characters to the ones I already printed... I want to print only the next 25 characters in the message!! any ideas? if (!isset($_GET['page'])){ $page = 1; } else {$page = $_GET['page']; } $max_results = 5; $from = (($page * $max_results) - $max_results); mysql_connect("$host", "$username", "$password")or die("no conn DB"); mysql_select_db("$db_name")or die("no DB"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT 1"; $result=mysql_query($sql); while ($row = mysql_fetch_assoc($result)) { $id = $row["id"]; $string = $row["detail"]; } $message = strlen($string); if ($message > 25){ $partX=$page*25; $part=($partX)-25; echo "<table width='300' height='455'><tr><td>".substr($string, $part, $partX)."</td></tr></table>"; } //echo $string; ?> <?php $total_results= strlen($string); $total_pages = ceil ($total_results / $max_results); echo "<center>Page<br />"; if ($page > 1){ $prev = ($page - 1); echo "<a href='".$_SERVER['PHP_SELF']."?page=".$prev."'><<prev</a>"; } for ($i = 1; $i <= $total_pages; $i++){ if (($page) == $i){echo "$i ";} else {"<a href='".$_SERVER['PHP_SELF']."?page=".$i.">".$i."</a>";} } if ($page < $total_pages){$next = ($page + 1); echo "<a href='".$_SERVER['PHP_SELF']."?page=".$next."'>+>></a>";} echo "</center>"; mysql_close(); ?>
  17. right! I worked on it and it seems that strlen() function gives me a number of characters... the question is... how do I get the text printed... cause if I print the variable that contains the strlen () just appears the number of characters that the message in the DB has... if (!isset($_GET['page'])){ $page = 1; } else {$page = $_GET['page']; } $max_results = 1; $from = (($page * $max_results) - $max_results); mysql_connect("$host", "$username", "$password")or die("no conn a BD"); mysql_select_db("$db_name")or die("no puede seleccionar BD"); $sql="SELECT * FROM $tbl_name ORDER BY id DESC LIMIT $from, $max_results"; $result=mysql_query($sql); while ($row = mysql_fetch_array($result)) { $id = $row["id"]; $string = $row["topic"]; } $message = strlen($string); echo $message; (after this I have the "page select" part of the script only)
  18. thank you... I will start working on this and let you know how it goes!!!
  19. that sound just like what I need... which function counts characters? I guess, the rule for the different pages would be similar to a "paging results" from any DB... but I'm a bit lost in the count characters, where to start...
  20. Hello! I managed to page results from a mysql DB. Now the question is... I have a page where text is going to be loaded, is there a way to paging this text if it is very long... What is the rough idea to start with... thank you in advance!
  21. if (!isset($respondido)){ AconnectDBB (); $sql="SELECT * FROM $tbl_name ORDER BY `id` DESC LIMIT 1 "; $result=mysql_query($sql); //mysql_close ($conQuest); while ($row=mysql_fetch_array($result)){ $Quest = $row["Quest"];} //Here I echo a standard html table with the question itself, a background and plain images... } else {  //first insert the value: insAnswer (); //then echo a different table, with the results coming from the DB and a php image: // $sqlSi="SELECT * FROM datos WHERE R = 's'"; $sqlNo="SELECT * FROM datos WHERE R = 'n'"; $sqlNS="SELECT * FROM datos WHERE R = 'ns'"; //$sqlNS="SELECT * FROM datos WHERE NS = 'ns'"; $sqlT="SELECT * FROM datos"; $resultadoSi = mysql_query($sqlSi); $totalSi=mysql_num_rows($resultadoSi); //echo "Sí ".$totalSi."<br>"; $resultadoNo = mysql_query($sqlNo); $totalNo=mysql_num_rows($resultadoNo); //echo "No ".$totalNo."<br>"; $resultadoNS = mysql_query($sqlNS); $totalNS=mysql_num_rows($resultadoNS); //echo "NS ".$totalNS."<br>"; $resultadoT = mysql_query($sqlT); $totalT=mysql_num_rows($resultadoT); //echo "T ".$totalT."<br>"; //redondeo Sí $redS = (($totalSi/$totalT))*100; $xS = round($redS); //echo "xS ".$xS."<br>"; //redondeo No $redN = (($totalNo/$totalT))*100; $xN = round($redN); //echo "xN ".$xN."<br>"; //redondeo NS $redNS = (($totalNS/$totalT))*100; $xNS = round($redNS); //echo "xNS ".$xNS."<br>"; mysql_close($con); //$xS =40; $yS =10; //$xN =60; $yN =25; //$xNS =45; $yNS =40; $pic = imagecreate(100, 70); $miAzul = imagecolorallocate($pic,128,149,206); $miAmarillo = imagecolorallocate($pic,255,249,204); $miGris = imagecolorallocate($pic,204,204,204); $miRojo = imagecolorallocate($pic,242,204,204); imagefilledrectangle($pic, 0, 20, $xS, $yS, $miRojo); imagefilledrectangle($pic, 0, 35, $xN, $yN, $miAmarillo); imagefilledrectangle($pic, 0, 50, $xNS, $yNS, $miGris); imageColorTransparent($pic, $miAzul); Imagepng($pic,"pic.png"); ImageDestroy($pic); echo "<img src='pic.png'>"; }
  22. thanks for that one! You see, I have an "if" working that prints a different subject in that <td> once you answered the question... if (!isset($answer)){ print question... } else { insertAnswer (); // this is a function that inserts into the DB and then print the results so far from the survey } So if I send it to the index.php the results wont show :(
  23. Hi! I created a small statistics script in my index, but when I vote my index loads again and if I refresh the page, the same vote is sent to the database... how could I stop this from happening? thank you!!!
×
×
  • 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.