Poll

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Poll

Postby Kenneth » Mon Aug 12, 2002 12:13 pm

Hey, again. Sorry, I'm just full of PHP stuff this week. But if you go to my site, http://www.coopercentral.org, there is a poll at the top. I used an SQL statement as such:

SELECT * FROM poll_table WHERE NOW() BETWEEN start AND end

I created a start and end field for my poll, so I can select them by there dates. My question is, how can I select them by there ids (id_sond) and by their dates? My friend said this but it didn't work:

SELECT * FROM poll_table WHERE id_sond = $id_sond AND Date Between start AND end

Any suggestions on this one? Thanks!! I really appreciate it!!

Ken Cooper

DoppyNL

Postby DoppyNL » Mon Aug 12, 2002 12:29 pm

To me there is nothing wrong with that query. I can't see why it shouldn't work. 8)
maybe you're just getting an empty result because there are no records that comply with the where-statement. :roll:

PHP doesn't return the mysql-error message, so perhaps you could try and run the actual query directly into mysql? :?:
or perhaps someone knows how to display the actual mysql-error message in php :P

:arrow: Greetz Daan

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Mon Aug 12, 2002 1:08 pm

Here's my question. Heres the sql statement:

SELECT * FROM poll_table WHERE id_sond = $id_sond AND Date Between start AND end

My question is, the AND DATE between part. What is the "DATE" part. Shoudn't be like

SELECT * FROM poll_table WHERE id_sond = $id_sond AND NOW() Between start AND end

I tryed that and it didn't work. Well, what I want to do is, like say the file is poll.php.

I want to be able to goto poll.php, and see the poll I put active by the date I specified, and go to like poll.php?id_sond=5. Do you get what I mean? Thanks a loT!!!

Ken Cooper

Jay

Postby Jay » Mon Aug 12, 2002 2:06 pm

dvdbinternet wrote:PHP doesn't return the mysql-error message, so perhaps you could try and run the actual query directly into mysql? :?:
or perhaps someone knows how to display the actual mysql-error message in php :P

:arrow: Greetz Daan

$result = @mysql_query($query,$connect) or die("<b>Query Failed</b><br>\n".$query."<br>\n".mysql_errno().": ".mysql_error());

Kenneth, now() can't be between start and end because they're all fixed values. The date part should refer to the 'date' field in the table you're searching on.

SELECT * FROM poll_table WHERE id_sond = $id_sond AND dateField BETWEEN startDate AND endDate

Though I prefer brackets:

SELECT * FROM poll_table WHERE (id_sond = $id_sond) AND (dateField BETWEEN startDate AND endDate)

But in this query it shouldn't make any difference to you though.

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Mon Aug 12, 2002 2:19 pm

Ya, thanks Jay, that was what I was thinking. When you mean Date Field, what do you mean. I already have the 2 fields. Do I create another field for a date? And if I do, do I put the date for each of the polls when they START? Sorry, I didn't get ya there. Thanks, I really appreciate it!!

Ken Cooper

Jay

Postby Jay » Tue Aug 13, 2002 3:14 am

Kenneth wrote:Ya, thanks Jay, that was what I was thinking. When you mean Date Field, what do you mean. I already have the 2 fields. Do I create another field for a date? And if I do, do I put the date for each of the polls when they START? Sorry, I didn't get ya there. Thanks, I really appreciate it!!

Ken Cooper

The date field is the field in your table in your database that stores the date for that particular record. The startDate and endDate are then two variables, which you obtain from your script, which you use to narrow down your search!

I think you've actually gone and put two date fields in your table, and are searching between those?? Which wouldn't work as they're static! All you need is one field, called Date or whatever, and set it to store the date in whatever format you like. You can then use this date to search on!

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Tue Aug 13, 2002 6:20 am

Thanks a lot. I actually have a date field on it. On that date field, do I enter the date for the start of that poll, or do I just leave it blank, but set it to "date"? Thanks!

KEn Cooper

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Tue Aug 13, 2002 6:43 am

Ya sorry for keeping this going and going, but I tried what you said. I added a date field, and made it "date". I tryed adding the date it started, and just left it blank, and still, it didn't work, no polls came up, and I couldn't select by id. If you want to know which poll I'm using, the site is:
http://www.alexphpteam.com - It's the MySQL one. Thats the poll I have. Actually, here's the code to the page, where I put the SQL statement in:

Code: Select all

<?php
$chemin120 = "$"."chemin";
if ($chemin == "") die ("<font face=\"Arial\" size=\"2\"><b>@lexPHPteam alert:</b> error, the variable $chemin120 isn't inform.</font>");

$abc_url = $PHP_SELF;
$where_my_slash = strrpos($abc_url, "/");
$where_my_slash++;
$sup_why = substr($abc_url, $where_my_slash);
$abc_url = str_replace($sup_why, "", $abc_url);
?>

<head>
<?php
if ($my_alex_function != "oui")
include ("$chemin/alex_functions2.inc.php");
?>
</head>

<?php
include ("$chemin/identif/logins.php");
include ("$chemin/identif/admin_infos.php");

//on détecte l'url d'origine
$alex_ext = $QUERY_STRING;
$nonono = 0;

$date = date("Y-m-d");
$table = "$table1";
@MYSQL_CONNECT ($serveur,$login2,$pass2) or die ("error, mysql connexion failed");
mysql_select_db("$base");

if ($id_sond == "")
$com_sql = "sond_actif='1'";
else
$com_sql = "id_sond='$id_sond'";

$query = "select id_sond,s_quest from $table WHERE id_sond = $id_sond AND date BETWEEN sond_actif AND archives";
$resultat = mysql_query($query);
$i = 1;
$id_sond3 = array();
$s_quest3 = array();
while ($ligne = mysql_fetch_array($resultat))
{
$id_sond3[$i] = $ligne["id_sond"];
$s_quest3[$i] = $ligne["s_quest"];
$i = $i + 1;
}
$i = 1;

$table = "$table2";
$query = "select id_rep,reponse,nbre_rep from $table where id_sond='$id_sond3[$i]' ORDER BY nbre_rep DESC";
$resultat = mysql_query($query);
$nblignes = mysql_num_rows($resultat);
$i = 1;
$id_rep3 = array();
$reponse3 = array();
$nbre_rep3 = array();
while ($ligne = mysql_fetch_array($resultat))
{
$id_rep3[$i] = $ligne["id_rep"];
$reponse3[$i] = $ligne["reponse"];
$nbre_rep3[$i] = $ligne["nbre_rep"];
$i = $i + 1;
}
$i = 1;
mysql_close();

$nbre_votant = 0;
$i=1;
while ($i <= $nblignes)
{
$nbre_votant = $nbre_rep3[$i] + $nbre_votant;
$i = $i + 1;
}
$i = 1;
if ($controle2 == "1" or $controle2 == "3") //cookies autorisés ?
   {//1
      while ($i <= $alex_max_sondage)
         {
            if ($alex_sondage_cook[$i] == $id_sond3[1])
               {
                  $nonono = 1;
                  break;
               }
            $i++;
         }
   }//1

$id_sondage =  $id_sond3[1];
$supp_ip_inv = 0; //on supprime pas les ip, on est à l'affichage
if (($controle2 == "2" or $controle2 == "3") && $nonono != "1" && ($suite != "ok3" && $choix_enr != "0"))
   {
      include ("$chemin/test_ip.php");
   }

if ($afficher_results == "1") //pour la partie admin
$nonono = 1;

if ($nblignes > "0")
{//////////////////////////////////////////////////si sondage, on entre
if (($nonono != "1" && $for_previsulualisation != "2") or $for_previsulualisation == "1")
{//ert

$pas_aff_archives = 0;
include ("$chemin/aff_voter.php");

}//ert
else
{//tre

$bis_chem = "$chemin/images/$nom_image2";
include("$chemin/aff_resultats.php");

}//tre
}///////////////////////////////////////fin si sondage on entre
else
{///////////////////////////////////////si pas de sondage
echo "<center><font face='Arial' size='1'>il n'y a pas de sondage valide sélectionné</font></center>";
}//////////////////////////////////////fin si pas de sondages
?>

Jay

Postby Jay » Tue Aug 13, 2002 11:48 am

When you added the date field to the DB, did you add dates for each record? They won't fill themselves in.

BTW, we're here to help you help yourself. We're not freelance PHP developers who'll do your donkey work for free! Sit down, get a good book, and learn PHP. If you're seriously stuck, we'll help you. But you're coming up with basic problems that show a serious lack of understanding.

Please, help yourself to a good book! :wink:

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Tue Aug 13, 2002 11:51 am

Sorry. I did buy php books. 2 of them, and one helps and the other doesn't. I guess I will just have to test it out more. Sorry for bugging.

Ken Cooper


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest