i8grand Posted March 23, 2010 Share Posted March 23, 2010 I am trying to insert an 81 character length string into my website from my database! I have stored the string in a table and am trying to insert each character into individual cells in a 9 x 9 grid. I have the following code but think I am doing something stupid, can anyone help!? <?php $puzzle = $_REQUEST["thisPuzzle"]; $dbQuery = "SELECT * FROM puzzlelevel, puzzle ". "WHERE puzzlelevel.id = puzzle.levelId AND puzzlelevel.id = $puzzle"; $result = mysql_query($dbQuery,$db); $dbRow = mysql_fetch_array($result); /*$puzzlelevelid = $dbRow[0]; $puzzlelevel = $dbRow[1]; $puzzleid = $dbRow[2]; $solution = $dbRow[3];*/ $startGrid = $dbRow[4]; //levelid = dbRow[5]; ?> <script type="text/javascript"> var startGrid="<?php$startGrid?>"; </script> <div id="puzzle"> <table class="table"> <tr> <td width="45" height="45"><script>document.write(startGrid.charAt(0));</script></td> the last line is the first of the cells! thisPuzzle is called from the previous page and does work, the problem lies when i try to call the startGrid field from my puzzle table and then try to get the first chracter from this and insert it into the first cell. I am trying to create a sudoku puzzle! Am I doing something stupid!? Any help would be brilliant, thank you Link to comment https://forums.phpfreaks.com/topic/196243-getting-a-string/ Share on other sites More sharing options...
Pawn Posted March 23, 2010 Share Posted March 23, 2010 This: var startGrid="<?php$startGrid?>"; ...won't do anything. If you want the fast echo syntax use var startGrid="<?=$startGrid?>" Or the more obvious var startGrid="<?php echo $startGrid; ?>" Also avoid mysql_fetch_array unless you need both associative and numeric indices. In this case, use mysql_fetch_row. Be sure to run mysql_real_escape_string on your $_REQUEST data before using it in your query. Link to comment https://forums.phpfreaks.com/topic/196243-getting-a-string/#findComment-1030596 Share on other sites More sharing options...
oni-kun Posted March 23, 2010 Share Posted March 23, 2010 var startGrid="<?=$startGrid?>" Why are you using short tags? <?php=$startGrid?> Link to comment https://forums.phpfreaks.com/topic/196243-getting-a-string/#findComment-1030604 Share on other sites More sharing options...
Pawn Posted March 23, 2010 Share Posted March 23, 2010 Lazy fingers! Link to comment https://forums.phpfreaks.com/topic/196243-getting-a-string/#findComment-1030608 Share on other sites More sharing options...
salathe Posted March 23, 2010 Share Posted March 23, 2010 Why are you using short tags? <?php=$startGrid?> Why are you using invalid syntax? Link to comment https://forums.phpfreaks.com/topic/196243-getting-a-string/#findComment-1030679 Share on other sites More sharing options...
Pawn Posted March 23, 2010 Share Posted March 23, 2010 I knew I had a reason! Link to comment https://forums.phpfreaks.com/topic/196243-getting-a-string/#findComment-1030716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.