Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2012, 10:48 PM
DustyJoe DustyJoe is offline
 
Join Date: Dec 2007
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Hey there, my PHP friends. Help please =)

I'm having trouble with spaces within mysql table contents.

Everything pulls from the database fine, spaces and all... when I pull using an integer associated with that particular row, now when I try and pull from the database based upon a string with a space, it does not seem to pull the entire sting. Just the data before the space.

For instance, when I try to select and pull "AMC - Gremlin"..
I get Unknown column 'AMC' in 'where clause'

Here is the start:
Code:
$query = "SELECT * FROM BAMFG_vehicle"; 
$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){

$output .= "<tr>
		<td width=100><img src='blank_img.gif'</td>
		<td><a href='bamfg_vehicle.php?do=view_vehicle&id=".$row['vehicle_id']."'>".$row['year']." - ".$row['make_model']."</a></td>
		<td width=50>".$row['view_cnt']."</a></td>
	</tr>";

$output2 .= "<OPTION VALUE=".$row['make_model'].">".$row['make_model']."";
}
Here is the code within the template:
Code:
<form action="bamfg_vehicle.php?do=search_vehicle" method="post" enctype="multipart/form-data">
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<input type="hidden" name="s" value="{vb:raw session.sessionhash}" />

<table width="500" border="1" align="center">
<tr><td width="80">
<SELECT SIZE="6" NAME="year">
<OPTION VALUE="2010"> 2013
<OPTION VALUE="2010"> 2012
<OPTION VALUE="2010"> 2011
<OPTION VALUE="2009"> 2009
<OPTION VALUE="2008"> 2008
<OPTION VALUE="2007"> 2007
<OPTION VALUE="2006"> 2006
<OPTION VALUE="2005"> 2005
<OPTION VALUE="2004"> 2004
<OPTION VALUE="2003"> 2003
</SELECT>
</td>

<td align="left">
<SELECT SIZE ="6" NAME="make_model">
    {vb:raw output2}
</SELECT>
<br>
</td>
</tr>
<tr><td colspan="2" align="right">
<input type="submit" />
</form>
</td></tr>
</table>

Here is my query code:

Code:
if($_REQUEST['do'] == 'search_vehicle') {

$year = $_POST['year'];
$make_model = $_POST['make_model'];

$query = "SELECT * FROM BAMFG_vehicle WHERE make_model = $make_model";  
$result = mysql_query($query) or die(mysql_error()); 

while($row = mysql_fetch_array($result)) 
{ 
$vehicle_id = $row['vehicle_id'];
$year = $row['year']; 
$make_model = $row['make_model']; 

}



// *** SEND VARIABLES TO TEMPLATE
$templater = vB_Template::create('BAMFG_vehicle_view');
	$templater->register_page_templates();
	$templater->register('navbar', $navbar); 
	$templater->register('vehicle_id', $vehicle_id);
	$templater->register('year', $year);
	$templater->register('make_model', $make_model);
print_output($templater->render());
}
Reply With Quote
  #2  
Old 01-08-2012, 12:00 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The value needs quotes around it, so something like:

Code:
$query = "SELECT * FROM BAMFG_vehicle WHERE make_model = '$make_model'";
Reply With Quote
  #3  
Old 01-13-2012, 03:59 PM
DustyJoe DustyJoe is offline
 
Join Date: Dec 2007
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the help before, I have one more thing kicking my butt though..

my output code
Code:
$output2 .= "<OPTION VALUE=".$row['make_model'].'>'.$row['make_model']."";
produces this respectively.
Code:
<OPTION VALUE= AMC - Gremlin> AMC - Gremlin
I've tried different configurations of quotes and such with no avail, I cannot seem to get quotes to appear round the make_model variable within the code. The year is perfect, but the text is kicking my butt.
Reply With Quote
  #4  
Old 01-13-2012, 04:03 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Try this:

PHP Code:
$output2 .= '<OPTION VALUE="' $row['make_model'] . '">' $row['make_model']; 
Reply With Quote
Благодарность от:
Lynne
  #5  
Old 01-13-2012, 04:10 PM
DustyJoe DustyJoe is offline
 
Join Date: Dec 2007
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That worked perfectly, thank you much.

You have helped me several times with random questions here and I really appreciate the time you take!

I'm slowly learning.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:58 PM.


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.06901 seconds
  • Memory Usage 2,209KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (6)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (1)post_thanks_box_bit
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete