how about i make a thread where i put all n00b questions

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

Code: Select all

$updateip = "UPDATE ".cms_dp_prefix()."module_poll SET lastip='$pollip' WHERE poll_id='$pollid'";
$dbresult = $db->Execute($updateip);
$answerquery = "SELECT * FROM ".cms_dp_prefix()."module_poll_answers WHERE poll_answer_id='$theanswer'";
$dbresult = $db->Execute($answerquery);
		
while($answerrow = $dbresult->FetchRow())
i want '''while($answerrow...''' to fetch from answerquery but not updateip, will it work like it is shown?

answered it on my own :cry:
Last edited by Bewbs on Tue Oct 19, 2004 11:38 pm, edited 1 time in total.
Bewbs

another question

Post by Bewbs »

HEre is the error message:

Code: Select all

Fatal error: Call to a member function on a non-object in /home/bewbsco/public_html/V2/modules/Poll/modulefunctions.php on line 243
here is the section of code in question:

Code: Select all

function viewanswers($pollid,$question)
{
	$db = $cms->db;
	$query = "SELECT * FROM ".cms_db_prefix()."module_poll_answers WHERE poll_id=$pollid ORDER BY poll_answer_id ASC";
	$dbresult = $db->Execute($query);
	$num_answers = $dbresult->RowCount();
	$counter = 1;

		while($answerrow = $dbresult->FetchRow())
		{
			$answerid = $answerrow['poll_answer_id'];
			$radiob = ("<input type=radio name=theanswer value=$answerid");
			if($counter==1)
			{
				$radiob = $radiob . " checked>";
			}
			else
			{
				$radiob = $radiob. ">";
			}
			echo $radiob;
			echo $answerrow['poll_answers']."<br>";
			$counter++;
		}
}
ive poured over said code for atleast two hours, and cannot see anything wrong, perhaps you can see the error?
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

/me kneels before the almighty wishy
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm
Location: Fairless Hills, Pa USA

how about i make a thread where i put all n00b questions

Post by Ted »

As I sit on my throne of CMS and look over my subjects...

Pfft. Yeah, right. If I ever go on a power trip, please smack me around until I'm put back in place. Thanks. :)
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

Code: Select all

function activatepoll($pollid,$cms)
{
	$db = $cms->db;
	$changesindb = "UPDATE ".cms_db_prefix()."module_poll SET poll_active='no' WHERE poll_active='yes'";
	$changesindb = "UPDATE ".cms_db_prefix()."module_poll SET poll_active='yes' WHERE poll_id=$pollid";
	$dbresult = $db->Execute($changesindb);
	return firstscreen();
}
would i have any problems doing it like that?
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

executing only one line of code?

Code: Select all

	$changesindb = "UPDATE ".cms_db_prefix()."module_poll_answers SET poll_result='$calc' WHERE poll_answer_id='$theid'";
i tried using $dbresult = $db->Execute($changesindb); but it didnt take
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

notes:

cms_mapi_user_form_start/end

[21:12] To do what? _start action" value="dosomething" /> _end
[21:12] No check for $params[$id . 'action'] and do something if it exists
[21:13] s/No/Now
Bewbs

code first

Post by Bewbs »

Code: Select all

function calculatevote($pollid, $theanswer, $pollip, $cms)
{
	$db = $cms->db;
	$ipquery = "SELECT * FROM ".cms_db_prefix()."module_poll WHERE poll_lastip='$pollip'";
	$dbresult = $db->Execute($ipquery);
	$checkrows = $dbresult->RowCount();
	
	if($checkrows==0)
	{
		$voted='no';
	}
	else
	{
		$voted='yes';
	}
	
	if($voted=='no')
	{	
		$db = $cms->db;
		$updateip = "UPDATE ".cms_db_prefix()."module_poll SET poll_lastip='$pollip' WHERE poll_id='$pollid'";
		$execute = $db->Execute($updateip);
		$answerquery = "SELECT * FROM ".cms_db_prefix()."module_poll_answers WHERE poll_answer_id='$theanswer'";
		$dbresult = $db->Execute($answerquery);
		
		while($answerrow = $dbresult->FetchRow())
		{
			$newvote = $answerrow['poll_votes']+1;
		}
		
		$db = $cms->db;
		$changesindb = "UPDATE ".cms_db_prefix()."module_poll_answers SET poll_votes='$newvote' WHERE poll_answer_id='$theanswer'";
		$execute = $db->Execute($changesindb);
		$answerquery = "SELECT * FROM ".cms_db_prefix()."poll_answers WHERE poll_id=$pollid";
		$dbresult = $db->Execute($answerquery);
		$num_answers = $dbresult->RowCount();
		$total=0;
	
			while($answerrow = $dbresult->FetchRow())
			{
				$answer[] = $answerrow['poll_answers'];
				$votes[] = $answerrow['poll_votes'];
				$id[] = $answerrow['poll_answerid'];
			}
			for($counter=0;$counter<$num_answers;$counter++)
			{
				$total=$total+$votes[$counter];
			}
			for($counter=0;$counter<$num_answers;$counter++)
			{
				if($votes[$counter]!=0)
				{
					$votecalc[] = 100/$total*$votes[$counter];
					
					if($votecalc[$counter]>=10)
					{$votetotal = substr($votecalc[$counter],0,2);}
					if($votecalc[$counter]==100)
					{$votetotal = substr($votecalc[$counter],0,3);}
					if($votecalc[$counter]<10)
					{$votetotal = substr($votecalc[$counter],0,1);}
					if($votecalc[$counter]==0)
					{$votetotal=0;}
				}
				else
				{
					$votecalc[] = 0;
					$votetotal=0;
				}
				$theid = $id[$counter];
				
				$calc = $votecalc[$counter];
				$db = $cms->db;
				$changesindb = "UPDATE ".cms_db_prefix()."module_poll_answers SET poll_result='$calc' WHERE poll_answer_id='$theid'";
				$execute = $db->Execute($changesindb);
				
		}
	}
	else
	{
		echo "<center><font color=990000>Your vote is not counted, Please wait a while before voting again.</font></center><br>";
	}
}

function viewresults($pollid, $question, $cms)
{
	$db = $cms->db;
	$resultquery = "SELECT * FROM ".cms_db_prefix()."module_poll_answers WHERE poll_id=$pollid ORDER BY poll_answer_id ASC";
	$dbresult = $db->Execute($resultquery);				
	while($resultrow = $dbresult->FetchRow())
	{
		echo "<B>".$resultrow['poll_answers']."</B><BR>";
		
		if($resultrow['poll_result']>0)
		{
			echo "<img src='images/blue.gif' width=".$resultrow['poll_result']." height='10'>";
		}
			echo $resultrow['poll_result']."% (".$resultrow['poll_votes']." votes)<br>";
	}
}
function poll_module_executeuser($cms, $id, $return_id, $params)
{
include "modules/Poll/config.php";
$db = $cms->db;
$query = "SELECT * FROM ".cms_db_prefix()."module_poll WHERE poll_active='yes'";
$dbresult = $db->Execute($query);
$numrows = $dbresult->RowCount();
$pollip = $GLOBALS['REMOTE_ADDR'];

if($numrows==0)
{
	$question = "No poll Active";
	$pollid = 0;
}
else
{
while($poll = $dbresult->FetchRow())
{
	$question = $poll['poll_question'];
	$pollid = $poll['poll_id'];
}
}

echo "<form name='pollform' method='post'>";
echo "<table width='200' border='0' cellspacing='0' cellpadding='0'>";
echo "<tr>";
echo "<td bgcolor='$titlebgcolor'><div align='center'>";

if($boldtitle==true)
{echo "<strong>";}

echo "<font color='$fontcolor' size='$titlesize' face='$fontstyle'>Poll version $version</font>";

if($boldtitle==true)
{echo "</strong>";}

echo "</div></td></tr>";

echo "<tr>";
echo "<td bgcolor='$bgcolor'>";
echo "<font color='$fontcolor' size='$fontsize' face='$fontstyle'>$question<br><br>";

if(!isset($poll_submit) && !isset($showresult))
{
	viewanswers($pollid, $question, $cms);
}
if(isset($showresult) && !isset($poll_submit))
{
	viewresults($pollid, $question, $cmst);
}

if(isset($poll_submit))
{	
	if(!isset($theanswer))
	{
		viewanswers($pollid, $question, $cms);
	}
	else
	{
		calculatevote($pollid, $theanswer, $pollip, $cms);
		viewresults($pollid, $question, $cms);
	}
	
}
echo "<div align='center'>";
echo "<br>";

if(!isset($poll_submit) && !isset($showresult))
{
	echo "<input name='poll_submit' type='submit' value='Vote'> ";		// Vote Button
	echo "<input name='showresult' type='submit' value='View Results'>";	// View results Button
}

echo "<br>";
echo "<a href='index.php?page=".$cms->variables['page']."&action=pastpoll'>View Other Polls</a>";
echo "<br><br></font></div></td></tr></table></form>";
}

the question/problem is that when the vote/view results buttons are pressed nothing happens, i believe this is becase one or more sql commands are not executing, ive been working on this poll program since 8ish this morning and my brain is scrambled, any advice/help would be great. tia. gg. goodnight
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

this

Code: Select all

	$resultquery = mysql_query("SELECT * FROM poll_answers WHERE poll_id=$pollid ORDER BY poll_answer_id ASC");
				
	while($resultrow = mysql_fetch_array($resultquery))
should look like

Code: Select all

	$db = $cms->db;
	$resultquery = "SELECT * FROM ".cms_db_prefix()."module_poll_answers WHERE poll_id=$pollid ORDER BY poll_answer_id ASC";
	$dbresult = $db->Execute($resultquery);				
	while($resultrow = $dbresult->FetchRow())
right?
Bewbs

how about i make a thread where i put all n00b questions

Post by Bewbs »

could i do this in say functions.db.inc.php

Code: Select all

function connect() {
  $gCms;
  global $conn;

  $conn = $cms->db;

  if( !$conn ) {
	  echo "Couldn't connect to database!<BR>";
  }

    mysql_select_db(dbname);
}

function query($query) {
  // do query
  $gCms;
  global $conn;

  $result = $db->Execute($query, $conn);


  if (!$result) {
      echo "Invalid SQL: ".$query." :: ".$conn;
  }

  return $result;
}

function fetch($result) {
  $gCms;
   if (isset($result)) {

     $row = $db->FetchRow($result);

   } else {

     echo "Invalid Query Fetch";

   }

    return $row;
}

function num_rows($result) {
  $gCms;
   // returns number of rows in query
   return $db->RowCount($result);
}

function close() {
  $gCms;
  // closes connection to the database

  return $db->Close();
}
and then use said functions to execute code in other functions??
Post Reply

Return to “Developers Discussion”