vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   What is the big complication? (https://vborg.vbsupport.ru/showthread.php?t=104014)

Lionel 12-30-2005 04:03 AM

What is the big complication?
 
The table says it clearly:
Quote:

a:5:{i:0;s:0:"";i:1;s:2:"38";i:2;s:0:"";i:3;s:1:"4 ";i:4;s:2:"78";}
5 items are in array. Values are at item 2, 3 and 4 (counting from 0)
Theorically seems easy to reinsert those values in same array textboxes
so why is this not doing the job?

PHP Code:

$predminutes1=unserialize($getplayers1['minutes1']);
for( 
$i=0$i count($predminutes1);$i++) {
//echo $predminutes1[$i];
$minutes1="<input type=\"text\" name=\"predminutes1[]\" value=\"$predminutes1[$i]\" size=\"10\">";



Marco van Herwaarden 12-30-2005 09:16 AM

I guess what you want would be something like:
PHP Code:

$predminutes1=implode(" "unserialize($getplayers1['gminutes1']));
$minutes1 ="<input type=\"text\" name=\"predminutes1[]\" value=\"$predminutes1\" size=\"10\">";
eval(
'$playerlist1 .= "' fetch_template('soccer_predictplayer1') . '";'); 


Lionel 12-30-2005 09:29 AM

1 Attachment(s)
Thanks Marco. At least I am getting somewhere, but it displays all the values in all the textboxes.

5 25 should have been on the second line, 15 on the third and 55 on the fourth. Nothing for first and last. :tired:

Marco van Herwaarden 12-30-2005 09:42 AM

Then please post a bigger part of your source. Impossible to see from this snippet exactly what you are trying to do, and advise you.

Lionel 12-30-2005 09:47 AM

Here is the full code. I had the same problem with the checkboxes. See how I got around it

PHP Code:

$getallplayers2 $DB_site->query(
SELECT cclpinternational_players.*, 
predictions2.predscore2 as score2, predictions2.predplayer2 as players2, 
predictions2.predminutes2 as gminutes2 FROM " 
TABLE_PREFIX "cclpinternational_players
LEFT JOIN cclpinternational_predictions as predictions2 
ON((cclpinternational_players.teamid=predictions2.teamid2) 
AND (predictions2.userid='
$bbuserinfo[userid]'))
WHERE teamid='
$tid2
"
);
if (
$DB_site->num_rows($getallplayers2) == 0)
{
$playerlist2="<tr><td colspan=\"5\" align=\"center\"><p><span class=\"smallfont\"><strong><font 
color=\"#99000\">Line up is not available yet or no line up</font></strong></span></p></td></tr>"
;
}
else { 
while (
$getplayers2 $DB_site->fetch_array($getallplayers2))
{
$predscore2=$getplayers2['score2'];
$playerid2=$getplayers2['id'];
$playerlname2=$getplayers2['lname'];
$playerfname2=$getplayers2['fname'];
$playerposition2=$getplayers2['position'];
$playernumber2=$getplayers2['number'];
$playerinfo2=$getplayers2['info'];
$playerphoto2=$getplayers2['photo'];
$predplayer2="$playerlname2 $playerfname2";
$player2=unserialize($getplayers2['players2']);
if (
$predplayer2==$player2[0] OR $predplayer2==$player2[1] OR $predplayer2==$player2[2] OR 
$predplayer2==$player2[3] OR $predplayer2==$player2[4] OR $predplayer2==$player2[5] OR $predplayer2==$player2[6] OR 
$predplayer2==$player2[7] OR $predplayer2==$player2[8] OR $predplayer2==$player2[9] OR $predplayer2==$player2[10] OR 
$predplayer2==$player2[11] OR $predplayer2==$player2[12] OR $predplayer2==$player2[13] OR $predplayer2==$player2[14] OR 
$predplayer2==$player2[15]) 
{
$checked "checked";}else { $checked "";}
$checkbox2 ="<input type=\"checkbox\" name=\"predplayer2[]\" value=\"$predplayer2\" $checked>";
$predminutes2=unserialize($getplayers2['gminutes2']);
for( 
$i2=0$i2 count($predminutes2); $i2++) {
$minutes2="<input type=\"text\" name=\"predminutes2[]\" value=\"$predminutes2[$i2]\" size=\"10\">"
}
eval(
'$playerlist2 .= "' fetch_template('soccer_predictplayer2') . '";');


That was the original which displays only the last value in all boxes, then your changes.
PHP Code:

 $predminutes1=implode(" "unserialize($getplayers1['gminutes1']));
$minutes1 ="<input type=\"text\" name=\"predminutes1[]\" value=\"$predminutes1\" size=\"10\">"

I am using the same code for team1 versus team2 (opponent) renaming the queries 1 and 2

Marco van Herwaarden 12-30-2005 10:08 AM

Sorry but i really can't advice, still not enough info. You are confusing with your examples. In the screenshot you are talking about the values 5, 25, 15 & 55, but the serialized array is showing totally different values.

I will need to know how to relate the array elements to the current player (PS if those 4 values are stored for 1 player, why don't they all apply to that player?)

Also posting the templates you are using might help.

....And, please please please, for yourself and others, do some decent line indentions, it will make your code so much easier to read.

PS I changed the above to the following, waiting on your feedback:
PHP Code:

$getallplayers2 $DB_site->query("SELECT cclpinternational_players.*
  , predictions2.predscore2 as score2
  , predictions2.predplayer2 as players2
  , predictions2.predminutes2 as gminutes2 
  FROM " 
TABLE_PREFIX "cclpinternational_players
  LEFT JOIN cclpinternational_predictions as predictions2 
    ON((cclpinternational_players.teamid=predictions2.teamid2) 
  AND (predictions2.userid='
$bbuserinfo[userid]'))
  WHERE teamid='
$tid2
 "
);
if (
$DB_site->num_rows($getallplayers2) == 0)
{
 
$playerlist2="<tr><td colspan=\"5\" align=\"center\"><p><span class=\"smallfont\"><strong><font 
 color=\"#99000\">Line up is not available yet or no line up</font></strong></span></p></td></tr>"
;
}
else
{
 while (
$getplayers2 $DB_site->fetch_array($getallplayers2))
 {
  
$predscore2=$getplayers2['score2'];
  
$playerid2=$getplayers2['id'];
  
$playerlname2=$getplayers2['lname'];
  
$playerfname2=$getplayers2['fname'];
  
$playerposition2=$getplayers2['position'];
  
$playernumber2=$getplayers2['number'];
  
$playerinfo2=$getplayers2['info'];
  
$playerphoto2=$getplayers2['photo'];
  
$predplayer2="$playerlname2 $playerfname2";
  
$player2=unserialize($getplayers2['players2']);
  
$checked = (in_array($predplayer2$player2) ? "checked" "");
  
$checkbox2 ="<input type=\"checkbox\" name=\"predplayer2[]\" value=\"$predplayer2\" $checked>";
  
  
$predminutes2=implode(" "unserialize($getplayers2['gminutes1']));
  
$minutes2 ="<input type=\"text\" name=\"predminutes2[]\" value=\"$predminutes2\" size=\"10\">";  
  eval(
'$playerlist2 .= "' fetch_template('soccer_predictplayer2') . '";');
 }  



Lionel 12-30-2005 10:16 AM

OK, as I am doing for 2 teams, here is the other serialize

PHP Code:

 a:5:{i:0;s:0:"";i:1;s:4:"5 25";i:2;s:2:"15";i:3;s:2:"55";i:4;s:0:"";} 

templates that I use

Main template

PHP Code:

 <form name="getcup">
<
table cellpadding="6" cellspacing="0" border="0" width="100%" class="tborder" align="center"> <tr> <td class="tfoot">
<
select name="cupid" onChange="MM_jumpMenu('parent',this,0)">
<
option value="#" selected>View other schedules</option>
$cuplist
</select>
</
td><td width="100%" class="tfoot"><strong><span style="float:right;">&raquo;&raquo; <a href="international/index.php?opt=schedule&divid=$thedivision&season=$seasonid">Full Standings</a>&nbsp;</span>$mycupname</strong></td></tr></table></form>
<
strong><font color="red">Under ConstructionAny predictions will be deleted.</font></strong>
<
table align="center" border="0" cellpadding="$stylevar[cellpadding]cellspacing="$stylevar[cellspacing]class="tborder" width="100%">
 <
tr><td align="right" colspan="10" class="alt1"><span class="smallfont"><if condition="$prediction"><a href="#">View predictions for $t1 vs $t2</a> | </if><a href="#">View all predictions</a> | <a href="#">View your predictions</a></span>&nbsp;</td></tr>
  <
tr
     <
td class="thead">Date</td>
    <
td align="center" class="thead">Time</td
    <
td class="thead">Location</td>
<
td class="thead">Team</td>
    <
td width="18" class="thead">Flag</td>
<
td colspan="2" align="center" class="thead">Score</td>
       <
td width="18" class="thead">Flag</td>
    <
td class="thead">Team</td>
<
td class="thead">Group</td>
      </
tr
$currentsched$predict
</table

Soccer_predict template ($predict)

PHP Code:

<form name="prediction" method="post" action"interschedule.php">
<
input type="hidden" name="seasonid" value="$seasonid">
<
input type="hidden" name="divid" value="$thedivision">
<
input type="hidden" name="teamid1" value="$tid1">
<
input type="hidden" name="teamid2" value="$tid2">
<
input type="hidden" name="gameid" value="$gameid">
<
input type="hidden" name="do" value="dopredict">
  <
tr
     <
td><span class="smallfont">$d</span></td>
    <
td align="center"><span class="smallfont">$t</span></td>
    <
td><span class="smallfont">$l</span></td>
<
td><span class="smallfont"><a href="international/index.php?opt=viewteam&id=$tid1&sid=$seasonid"><strong>$t1</strong></a></span></td>
    <
td width="18"><img src="international/images/smallflags/$t1.gif"></td>
 <
td align="center" class="alt1"><input name="predscore1" value="$predscore1type="text" size="1" maxlength="2">
</
td> <td align="center" class="alt1"><input name="predscore2" type="text" size="1" value="$predscore2maxlength="2">
</
td>
       <
td width="18"><img src="international/images/smallflags/$t2.gif"></td>
    <
td><span class="smallfont"><a href="international/index.php?opt=viewteam&id=$tid2&sid=$seasonid"><strong>$t2</strong></a></span></td>
<
td><span class="smallfont"><a title="$cupnamehref="interstandings.php?g=$gamegroup&cupid=$thecupid">$gamegroup</a></span></td>
      </
tr>
<
tr><td align="center" colspan="10"><span class="smallfont">Predictions may be changed anytimeup to 30 seconds before the game start. <br />We use the game location timezone for prediction cutoff time.  <br /><strong><font color="#990000">Optional:</font></strongYou may also predict the scorer's name and the minutes that he will score.<br />Separate minutes by a <b>space</b> for same player with more than one goal.(e.g.: 21 46 65)<br />Those values will be used in case of multiple winners. First by name, then by minutes if we still have multiple winners.</span></td></tr>
<tr><td width="50%" valign="top" align="center" colspan="5">
<table class="tborder" width="100%" cellspacing="1" cellpadding="2" border="0"><tr><td class="thead" colspan="5" align="center">$t1</td><tr>
<tr class="alt2"><td>&nbsp;</td><td><span class="smallfont">Player Name</span></td><td align="center"><span class="smallfont">#</td><td><span class="smallfont">Position</td><td nowap align="center"><span class="smallfont">Minutes will Score</span></td></tr>
$playerlist1
</table>
 </td>
<td width="50%" valign="top" align="center" colspan="5"><table class="tborder" width="100%" cellspacing="1" cellpadding="2" border="0"><tr><td class="thead" colspan="5" align="center">$t2</td><tr>
<tr class="alt2"><td>&nbsp;</td><td><span class="smallfont">Player Name</span></td><td align="center"><span class="smallfont">#</td><td align="center"><span class="smallfont">Position</td><td nowrap align="center"><span class="smallfont">Minutes will Score</span></td></tr>
$playerlist2
</table>
</td></tr><tr><td colspan="10" align="center"> <input type="submit" name="submit" value="Submit Prediction" class="button" />
</td></tr></td></tr></form> 

and playerlist1 soccer_predictplayer1 template (identical to playerlist2)

PHP Code:

<tr><td width="5">$checkbox1</td><td width="45%" align="left"><span class="smallfont"><a href="international/playerinfo.php?pid=$playerid1">$playerlname1$playerfname1</a></span></td>
<
td width="10" align="center"><span class="smallfont">$playernumber1</span></td>
<
td align="center"><span class="smallfont">$playerposition1</span></td>
<
td align="center">
<
span class="smallfont">$minutes1</span></td>
</
tr

Wow, great code for the checkboxes. It works!!!

Marco van Herwaarden 12-30-2005 10:24 AM

Quote:

Originally Posted by Lionel
OK, as I am doing for 2 teams, here is the other serialize


PHP Code:
a:5:{i:0;s:0:"";i:1;s:4:"5 25";i:2;s:2:"15";i:3;s:2:"55";i:4;s:0:"";}

I am sorry but that don't make much sense to me. My Logic (:D) tells me you will have a table structure something like:

Game
- gameid

GameTeam (2 rows per game, one for each team??????)
- gameid
- teamid
- totalscore

GamePlayers
- gameid
- teamid
- playerinfo
- gminutes2 (a serialized array containing the minutes of all goals scored by any player for this game/team)

As you see you are storing the minutes from all players in the row about a single player, then you want out of that array to retrieve only the goals, the current player has made. How can you know which array element you need for a player, and why store the info of all players in the row about a single player.


PS Maybe better if you also give your table structure and some sample data.

Lionel 12-30-2005 10:39 AM

1 Attachment(s)
Here is a snaphop of my main predictions table

Here is how it works. Member comes on the site and select a game for predictions. He gets to put the scores for team1 and for team 2

then he gets to put who will score (from the checkboxes) and at what minute that score will happened in the textbox, separating 2 goals for same player by a space. (in my example I simulated a prediction for 5 goals and 4 inputs for minutes, one of them having scored twice, so same textbox has 2 value).

I have only one input per game per member, meaning in that structure I am posting in this post, a single line holds all the values serialized (although the prdplayer serialize was not necessary) . The rest is accomplish with LEFT JOIN. I am also posting how it looks in db.

And here is how I insert in the prediction table

PHP Code:

 if ($_POST['do']=='dopredict') {
if (!
$bbuserinfo['userid'] OR !($permissions['forumpermissions'] & CANVIEW))
{
print_no_permission();
}
$user=$bbuserinfo[userid];
$seasonid $_POST['seasonid'];
$thedivision $_POST['divid'];
$tid1 $_POST['teamid1'];
$tid2 $_POST['teamid2'];
$gameid $_POST['gameid'];
$predscore1 $_POST['predscore1'];
$predscore2 $_POST['predscore2'];
$predminutes1 serialize($_POST['predminutes1']);
$predminutes2 serialize($_POST['predminutes2']);
$tplayer1 serialize($_POST['predplayer1']);
$tplayer2 serialize($_POST['predplayer2']);
$DB_site->query("INSERT INTO cclpinternational_predictions(id,userid,gameid,divid,seasonid,teamid1,teamid2,predscore1,predscore2,predplayer1,predplayer2,predminutes1,predminutes2) VALUES ('NULL','$user','$gameid','$thedivision','$seasonid','$tid1','$tid2','$predscore1','$predscore2','".addslashes($tplayer1)."','".addslashes($tplayer2)."','$predminutes1','$predminutes2')");
 
$_REQUEST['forceredirect'] = 1;
$url "interschedule.php?cupid=$thedivision";
eval(
print_standard_redirect('redirect_predictionthanks'));



Marco van Herwaarden 12-30-2005 11:15 AM

Sorry but what you got is really confusing.

If you want help on this, send me you ICQ or MSN contact info in PM.


All times are GMT. The time now is 06:43 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02453 seconds
  • Memory Usage 1,904KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete