Jump to content

rchandran0023

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rchandran0023's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. nice, thank u for the posts, they have helped and il take ur advice about posting better.
  2. Im trying to implement the "little pic poll" in my site, but in the source its coded to diplay the images and radio buttons in a table, and the way it renders on the screen is in a straight colomn down, i want to have the picts render in like maybe 4 element wide rows going down, so first fill in the first row, then the second, so on. but as it is now it just has the picts showing each under the other. I see the code thats doing this, within the while statements, but cant figure how to do it, by imbeding another loop or what? Ne help MUCH appreciated and i will respect u forever!! Im showing all the source code, but its not all pertinant to my question. TY. include("lp_settings.php"); //include file containing general settings import_request_variables("p", "p_"); //import POST variables import_request_variables("c", "c_"); //import cookie variables if (!isset($c_votingstep)) { $votingstep=1; } else { $votingstep = $c_votingstep; } function SumArray($arr) { $h=count($arr); $in=0; $m=0; while ($in<$h) { $m += $arr[$in]; $in++; } return $m; } function getIP() { if (getenv("HTTP_CLIENT_IP")) $ip = getenv("HTTP_CLIENT_IP"); else if(getenv("HTTP_X_FORWARDED_FOR")) $ip = getenv("HTTP_X_FORWARDED_FOR"); else if(getenv("REMOTE_ADDR")) $ip = getenv("REMOTE_ADDR"); else $ip = "UNKNOWN"; return $ip; } function write2log ($linetoadd) { $rightnow=date("F j, Y, g:i a"); $fplog=fopen('lp_log.dat', "a"); fputs($fplog, getIP()."|".$rightnow."|".$linetoadd."\n"); fclose($fplog); } function ReadElements() { global $filename; $fp=fopen($filename, "r"); $file_contents=fread($fp,filesize($filename)-1); fclose($fp); $elements=explode("|",$file_contents); $h=(count($elements)-1)/4; $question=stripslashes($elements[0]); $in=0; while ($h>$in) { $item[$in]=$elements[(4*$in+1)]; $smallpic[$in]=$elements[(4*$in+2)]; $bigpic[$in]=$elements[(4*$in+3)]; $itemvoted[$in]=$elements[(4*$in+4)]; $in++; } return array ($item, $smallpic, $bigpic, $itemvoted, $question); } list ($item, $smallpic, $bigpic, $itemvoted, $question) = ReadElements(); if(isset($c_pollidcookie)) { if ($question != stripslashes($c_pollidcookie)) { $votingstep=1; } } setcookie("pollidcookie", $question, time()+$time_between_votes); if (isset($votingstep)) { function ShowTheStuff($item, $smallpic, $bigpic, $itemvoted, $graph_width, $graph_height) { $hector=count($itemvoted);$totalvotes=0;$in=0;$stepstr=''; $totalvotes=SumArray($itemvoted); $in=0; if ($totalvotes==0) { $totalvotes=0.0001; } while ($in<$hector) { $timesred=(int)((($itemvoted[$in]/$totalvotes))*$graph_width); $stepstr=$stepstr.'<table border=0><tr><td>&nbsp</td><td><font size="1">'.stripslashes($item[$in]).'</td></tr>'; $stepstr=$stepstr.'<tr><td align="center"><font size="1">'.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br><img width='.$graph_height.' height='.($graph_width-$timesred).' src="lp_0.gif"><br><img width='.$graph_height.' height='.$timesred.' src="lp_1.gif"></td>'; $stepstr=$stepstr.'<td><a href="#" OnClick="window.open(\''.$bigpic[$in].'\', \'GOto\', \'toolbar=no\');"><img src="'.$smallpic[$in].'" border=0></a></td></tr></table>'; //$stepstr=$stepstr.'<br><br>'; $in++; } return $stepstr; } } if (!isset($votingstep)) { $votingstep=1; } if ($votingstep==2) { if(!isset($p_radios)){ $votingstep=1; write2log("Clicked vote button without choosing an item"); } // detect if someone has clicked the voting button without choosing an item } if ($votingstep==1) { write2log("Enters Poll"); setcookie("votingstep","2",time()+$time_between_votes); $mainstr=$message1; $step1str='<form action="'.$callingfile.'" method="post" name="form1">'; $totalvotes=SumArray($itemvoted); $in=0; $datop=count($item); while($in<$datop){ $step1str=$step1str.'<table border=0><tr><td><input type="radio" name="radios" value="'.$in.'"></td><td><font size="1">'.stripslashes($item[$in]).'</td></tr>'; //$step1str=$step1str.'<tr><td align="center"><font size="1">'.(int)(($itemvoted[$in]/$totalvotes)*100).'%<br><img width='.$graph_height.' height='.($graph_width-$timesred).' src="lp_0.gif"><br><img width='.$graph_height.' height='.$timesred.' src="lp_1.gif"></td>'; $step1str=$step1str.'<tr><td>&nbsp</td><td><a href="#" OnClick="window.open(\''.$bigpic[$in].'\', \'GOto\', \'toolbar=no\');"><img src="'.$smallpic[$in].'" border=0></a></td></tr></table>'; //$step1str=$step1str.'<br><br>'; $in++; } $step1str=$step1str.'<br><input style="'.$buttonstyle.'" type="Submit" value="'.$vote_str.'"></form>'; } if ($votingstep==2) { setcookie("votingstep","3",time()+$time_between_votes); $mainstr=$message2; $itemvoted[$p_radios]=$itemvoted[$p_radios]+1; $totalvotes=SumArray($itemvoted); $fp=fopen($filename, "w"); $hector=count($item); $in=0; $linetoadd=$question.'|'; fputs($fp, $linetoadd); while($in<$hector) { $linetoadd=$item[$in].'|'.$smallpic[$in].'|'.$bigpic[$in].'|'.$itemvoted[$in].'|'; fputs($fp, $linetoadd); $in++; } fclose($fp); write2log("Vote received on ".$item[$p_radios]); $step2str=ShowTheStuff($item, $smallpic, $bigpic, $itemvoted, $graph_width, $graph_height); } if ($votingstep==3) { $mainstr=$message3; $totalvotes=SumArray($itemvoted); write2log("Views results"); $step3str=ShowTheStuff($item, $smallpic, $bigpic, $itemvoted, $graph_width, $graph_height); } ?>
  3. i have dloaded a nice little simple voting app but cant get it to work. It will not display the stats when the "view results" button is clicked. Iv tried to put "$results = $_POST['results'];" in different places in the code but the best i can get is it will pop up with the stats but they wont be correct. ??? Any help would be much appreciated and im sure it will help others as well. I am an official phpfreaks donating member. ......................................................................... <code> <? // $results = $_POST['results']; $filename = "poll.txt"; $fl=fopen($filename,'r'); $name = fgets($fl, 4096); $options[0] = fgets($fl, 5); $temp = $options[0]; while ($temp) { $theoptions[$temp] = fgets($fl, 4096); $temp = $temp - 1; } $temp = $options[0]; while ($temp) { $thevalues[$temp] = fgets($fl, 4096); $temp = $temp - 1; } fclose($fl); if ($results) { echo "$name<br>"; $temp = $options[0]; while ($temp) { if ($thevalues[$temp] == 0) { $percent = 0; } else { $tempnum = $options[0]; $total = 0; while ($tempnum) { $total += Trim($thevalues[$tempnum]); $tempnum = $tempnum - 1; } $percent = 100 * Trim($thevalues[$temp]) / $total; if (strlen($percent) > 4) { $percent = substr($percent, 0, 4); } } echo "$theoptions[$temp]: $percent% ($thevalues[$temp] votes)<br><br>"; $temp = $temp - 1; } } elseif ($vote) { echo "You voted for $theoptions[$optradio]<br>"; unlink($filename); $fl = fopen($filename, 'w'); fputs($fl, "$name"); fputs($fl, "$options[0]"); $temp = $options[0]; while ($temp) { fputs($fl, "$theoptions[$temp]"); $temp = $temp - 1; } $temp = $options[0]; while ($temp) { if ($temp == $optradio) { fputs($fl, "$thevalues[$temp]" + 1); fputs($fl, "\n"); $temp = $temp - 1; } else { fputs($fl, "$thevalues[$temp]"); $temp = $temp - 1; } } fclose($fl); } else { echo "$name<br>"; $temp = $options[0]; echo "<form method=\"post\" action=\"$PHP_SELF\">"; while ($temp) { echo "<input type=\"radio\" name=\"optradio\" value=\"$temp\"> $theoptions[$temp]<br>"; $temp = $temp - 1; } echo "<input type=\"submit\" name=\"vote\" value=\"Vote\">"; echo "<input type=\"submit\" name=\"results\" value=\"View Results\">"; } ?> </code>
  4. hey thefortress u f-ing rock dude, your response answered my question perfectly and I even learned something! I just wasnt sure where to nest that loop and how to set the count to 0 again. Brilliant! U are a php guru and i love u. I said if my question gets answered I would donate to phpfreaks and now I will and will be a regular member. I love this site. It is a crucial resourse now on my job.
  5. I query a database and print the info in a table. I need to print a new table header on each new page. Do I need to embed another loop somewhere so that like every 20 rows print a new table header, if so how, and where? Thank you so much for any help. Here is my code now: ... $result = mysql_query("SELECT u.file_number, u.unit_address1, u.bldg_num, u.apt, u.mutual, r.tel_num, r.res1_f_name, r.res1_l_name from unit u, resident_info r where u.file_number = r.file_number AND u.mutual = $mutual"); print "<table align='center'>"; // print headers for ($c=0; $c<mysql_num_fields($result); $c++) { print "<th>".mysql_field_name($result, $c)."</th>"; } // print table rows while( $record = mysql_fetch_array( $result )){ //$colors = array("#DCE1E7", "#E9EBEF"); $i = 0; if($i%2) { $color="#DCE1E7"; } else { $color="#E9EBEF"; } $colors = array($color, $i); print "<tr bgcolor=$color>"; for( $c=0; $c<mysql_num_fields( $result ); $c++ ) { print "<td align='center'>".$record[$c]."</td>"; } print "</tr>"; }} print "</table>"; ?>
×
×
  • 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.