Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to give a field a default value
JimR Offline
Junior Member
**
Posts: 15
Joined: Jun 2012
Post: #3
RE: How to give a field a default value
(02-26-2013 09:30 AM)ZiNgA BuRgA Wrote:  Parse error = your code is invalid regardless of where you put it.
I don't understand what your code is trying to do, more specifically, I don't understand the purpose of the database query.  If my guess is correct, you'd just put the following in the Default Value field:

Code:
<?=$sub.$build?>


That didn't work however here is the postbit template

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
include "llpg.php";
?>
{$ignore_bit}
<a name="pid{$post['pid']}" id="pid{$post['pid']}"></a>
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" colspan="4">
<tr class="menu">
			<td class="tcat tab at" title="Overview" style="cursor: pointer; text-align: center; width: 10%;border-right:1px solid black" abbr="tc1">
				<center><b>Overview</b></center>
			</td>
                            <td class="tab tcat" title="Garden Waste" style="cursor: pointer; text-align: center; width: 10%;border-right:1px solid black" abbr="tc2">
				<center><b>Garden Waste</b></center></td>
                              <td class="tcat tab" title="Commercial" style="cursor: pointer; text-align: center; width: 10%;border-right:1px solid black" abbr="tc3"><center><b>Commercial</b></center></td>
                               <td class="tcat tab" title="Notes"  style="cursor: pointer; text-align: center; width: 10%;border-right:1px solid black" abbr="tc4"><center><b>Notes</b></center></td>
				
                              <td class="tcat" width="60%">
			</td></tr></table>
<div id="tc1" class="content tbar">
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" colspan="4">
<tr>
<td class="tbar" valign="top"></td>
<td class="tbar" rowspan="10" valign="top" style="margin-top:10px;margin-left:5px;"><center><b>Property Status</b></center>
<div style="float:left;padding-left:110px;">Single Person <input type="checkbox" name=mybox value="1" disabled checked><br>Garden Waste <input type="checkbox" name=mybox1 value="0" disabled ><br>Recycle Bin&nbsp; &nbsp;&nbsp;&nbsp;<input type="checkbox" name=mybox value="1" disabled checked></div>
</td></tr>
<tr><td class="tbar" width="50%"><b><div style ="margin-left:10px">Current Contact</b></div>{$GLOBALS['threadfields']['name']}</td></tr>
<tr><td class="tbar" width="50%"><b><div style="margin-left:10px">Official Address</div><div style="margin-left:10px"></b>$addressblock<br></div></td></tr>
<tr><td class="tbar" colspan="4" width="100%"><hr></td></tr>

</table>
</div>
<div id="tc2" class="content tbar">
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" colspan="3">
<tr class="tbar"><td class="tbar"></td><td></td><td></td><td></td><td></td><td></td></tr>
<tr class="tbar"><td colspan="2" width="35%" valign="top">
<div class="tbar" style="border:1px solid black;border-radius:0.3em;float:left;width:100%;padding:0px;"><center><b>Customer Information</b></center>
<div class="tinput"><b>Name :</b></div><div style="float:left;">{$GLOBALS['threadfields']['name']}</div>
<div class="tinput"><b>Telephone No :</b></div><div style="float:left;">{$GLOBALS['threadfields']['tele']}</div>
<div class="tinput"><b>Payment Method :</b> </div><div style="float:left;">{$GLOBALS['threadfields']['paym']}</div>
<div class="tinput"><b>Payment Reference :</b> </div><div style="float:left;">{$GLOBALS['threadfields']['cref']}</div>
<div class="tinput"><b>PIMM Reference Number :</b> </div><div style="float:left;">{$GLOBALS['threadfields']['pimm']}</div>
<div class="tinput" style="padding-bottom:5px"><b>Customer Account Number :</b> </div><div style="float:left;">{$GLOBALS['threadfields']['dnum']}</div>
</div></td>
<td colspan="4" valign="top"><div class="tbar" style="border:1px solid black;border-radius:0.3em;float:left;width:98%;padding:5px;"><b><center>Logistical Information</center></b>
<table style="clear:both"><tr><td valign="top"><center><b>Collection Address</b></center><div><center>[b]THE ADDRESS FROM THREADFIELDS WILL GO HERE[/b]</center></div></td>
<td valign="top"><center><b>Collection Tags</b></center></div><div style="float:right;margin-right:20px;">{$GLOBALS['threadfields']['gass']}</div><div style="float:right;margin-right:20px;"><b>Assisted Collection</b></div>
<br><div style="float:right;margin-right:20px;">{$GLOBALS['threadfields']['da']}</div><div style="float:right;margin-right:20px;"><b>Difficult Access</b></div><br>
<div style="float:right;margin-right:20px;">{$GLOBALS['threadfields']['prob']}</div><div style="float:right;margin-right:20px;"><b>Problem Collection</b></div><br>
<div style="float:right;margin-right:20px;">{$GLOBALS['threadfields']['numb']}</div><div style="float:right;margin-right:20px;"><b>Number Of Bins</b></div>
</td></tr></table>
</div></td></tr>
</table>
</div>
<div id ="tc3" class="content tbar">
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder" colspan="4">
<tr>
<td class="tbar" valign="top"><b>Commercial Waste Pane</b></td>
<td class="tbar" rowspan="10" valign="top" style="margin-top:10px;margin-left:5px;"><center><b>Collection Detail</b></center>
<div style="float:left;padding-left:110px;">Is Twat <input type="checkbox" name=mybox value="1" disabled checked><br>Side Waste <input type="checkbox" name=mybox1 value="0" disabled ></div
</td></tr>
<tr><td class="tbar" width="50%"><b><div style ="margin-left:10px">Contact&nbsp&nbsp&nbsp</div></td></tr>
<tr><td class="tbar" width="50%"><b><div style="margin-left:10px">Billing Address</div><div style="margin-left:10px"></b><br></div></td></tr>
<tr><td style="background:#cedba4;" colspan="2"><hr></td></tr>

</table>
</div>
<div id ="tc4" class="content tbar">
<div class="post {$unapproved_shade}" style="{$post_visibility}" id="post_{$post['pid']}">
<div class="post_content">
		<div class="post_body" id="pid_{$post['pid']}">
		{$post['message']}
	</div>
	{$post['attachments']}
	{$post['signature']}
	<div class="post_meta" id="post_meta_{$post['pid']}">
		{$post['iplogged']}
	</div>

</div>
</div>
</div>
<div class="tbar">
	<span class="tbar" style="padding-left:10px;">
		{$post['button_email']}{$post['button_edit']}</span>
	
	</div>
</div>


and here is llpg.php

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
// llpg display functions
global $mybb, $db, $cache, $templates;
// pull the correct record from llpg table
$select=$db->query("select * from ".TABLE_PREFIX."llpg where NationalUPRN ='".$post['uprn']."'");
$result=$db->fetch_array($select);// can not fail as the field has to be populated and has been selected before
$sub = $result['SUBBUILDINGNAME'];
$build = $result['BUILDINGNAME']; 
$no = $result['BUILDINGNUMBER'];
$street = $result['STREETNAME'];
$local= $result['LOCALITYNAME'];
$town = $result['TOWN'];
$postcode= $result['POSTCODE'];
if ($mybb->settings['llpg_addressblock']==1) // do this if required N.B the single address lines are also returned
{
// produce a preformatted address
if ($sub <> null or $build <> null){$build=$build."<br>";} // add a br is populated
if ($no==null and $street == null and $local == null){$split=0;} // no option
if ($no<>null and $street == null and $local == null){$split=1;} // just house number
if ($no==null and $street <> null and $local == null){$split=2;} // just a street name
if ($no==null and $street == null and $local <> null){$split=3;} // just locality
if ($no<>null and $street == null and $local <> null){$split=4;} // number and locality
if ($no<>null and $street <> null and $local == null){$split=5;} // number and street
if ($no==null and $street <> null and $loacl <> null){$split=6;} // street and locality
if ($no <> null and $street <> null and $local <> null){$split=7;} // all 3
if ($sub <> null and $build <> null and $no == null){$split=8;} // commercial units ??
if ($sub == null and $build <> null and $street == null and $local == null){$split=9;}
if ($sub == null and $build <> null and $no == null and $local == null and $street <> null) {$street=$street."<br>";}
if ($sub <> null and $build <> null and $no == null and $local == null and $street <> null) {$street=$street."<br>";}
if ($sub == null and $no == null and $local == null and $street <> null) {$street= $result['STREETNAME'];}
//if ($sub <> null and $build <> null and $no <> null and $street <> null and $local == null) {}
switch ($split){ 
case 0:
// nothing presented just do the format
$sub=$sub."<br>";
break;
case 1:
die("case1");
// this can not happen unless the table is crashed
break;
case 2:
$Street=$street."<br>";
$local=$local."<br>";
break;
case 3:
$local=$local."<br>";
break;
case 4:
$local=$local."<br>";
break;
case 5:
$street=$street."<br>";
break;
case 6:
die("street + local");
// should never hit
break;
case 7:
$street=$street."<br>";
$local=$local."<br>";
//die("all 3");
break;
case 8:
$sub=$sub."<br>";
// should never hit this
break;
case 9:
//die("nine");
//$build=$build."<br>";
break;
case 200:
//die("here it is");
break;
default:
die("not thought of"); 
// have I missed something ?
}
 
if ($sub <>""){
$sub=$sub.' '; // add a space
}
if ($no <>""){
$no." "; 
}
$position = strpos($town, ",",$position);// we have a comma
 if ($position > 0){$town = str_replace(",","<br>",$town);}// replace the comma with <br>
// format the block
$addressblock = "$sub $build $no $street $local $town<br>$postcode";
// $addressblock is now formatted and in the template
}
// now add the collection address to our fields
// test if there is a row 
$select=$db->query("select * from ".TABLE_PREFIX."threadfields_data where tid ='".$post['tid']."'");
$num_rows = $db->num_rows($select); //rows for the record only 1 or 0
// if no row format the address
switch ($num_rows){
	case 0:
// no record add the default address to the collection address fields
// from the llpg table                  		
		break;
	case 1:
		// do nothing
		
		break;
}


?>

what I am  trying to do is if there is no record in the threadfields_data table, make the threadfields default to the data from the llpg table but if there is a record in the threadfields_data table do nothing.
the only reason I have tried to do this is that I want to save my users some time by supplying a default address which they can edit (as required) or would it be better to pre process the thread_fields data table with the default addresses (put them all in), as I have 65500 posts I would perfer to add the data as required rather than pre process them

02-27-2013 02:49 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
How to give a field a default value - JimR - 02-26-2013, 05:11 AM
RE: How to give a field a default value - JimR - 02-27-2013 02:49 AM

 Standard Tools
Forum Jump: