Click to See Complete Forum and Search --> : Creation Of HTML Display Table
Critical
04-08-2008, 01:35 PM
Hey guys.
So here is the breakdown on what I am trying to do.
1) SQL Query goes and retrieves Top 10 item_id rows.
2) PHP creates a table to display the data in and then fills the table until there is no more rows left to fill.
3) HTML page calls the PHP page via javascript to display the table.
Here is the SQL Query/PHP code:
$dbuser="******";
$dbpass="*******";
$dbname="********";
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$toptenquery="SELECT Top 10(item_id) AS toptenitem FROM eqdkp_items SORT BY item_id DESC";
// open the table and print a header row.
echo "<table align=right width=300>"
echo "<tr><th>Latest Loots</th></tr>\n";
if ($result=mysql_query($sql)) {
while ($row=mysql_fetch_row($result)) {
echo "<tr>".$row."</tr>";
}
} else {
echo "<!-- SQL Error ".mysql_error()." -->";
}
echo "</table>";
Here is the code to call the PHP page via the HTML page:
<script language="JavaScript" type="text/javascript" src="./datacall.php"
<script>
The goal of all of this is to have the top 10 items display in a table in the top right hand corner of the page (in the header).
The link to my site is: www.ep-guild.com and www.ep-guild.com/eqdkp
Thanks for your help and time.
- Critical
mayooresan
04-08-2008, 01:41 PM
I did understand your request clearly... but is dat what you mean??
<table> <?php echo '<tr><td>'.$row['firstItem'].'</td>'.$row['secndItem'].'</tr>'; ?></table>
kurby
04-08-2008, 02:00 PM
Your PHP is on the right track. mysql_fetch_row returns an array, so you need to treat it as such. Since you are only retrieving one column, just make sure you refer to it as row[0]. Also, forgot <td>. Other than that, are you getting some other error?
I assume every time an item is looted, whether it has or has not been looted before, it gets a brand new item_id?
$dbuser="******";
$dbpass="*******";
$dbname="********";
$chandle = mysql_connect("localhost", $dbuser, $dbpass)
or die("Connection Failure to Database");
mysql_select_db($dbname, $chandle) or die ($dbname . " Database not found. " . $dbuser);
$toptenquery="SELECT Top 10(item_id) AS toptenitem FROM eqdkp_items SORT BY item_id DESC";
// open the table and print a header row.
echo "<table align=right width=300>"
echo "<tr><th>Latest Loots</th></tr>\n";
if ($result=mysql_query($sql)) {
while ($row=mysql_fetch_row($result)) {
echo "<tr><td>".$row[0]."</td></tr>";
}
} else {
echo "<!-- SQL Error ".mysql_error()." -->";
}
echo "</table>";
Critical
04-08-2008, 02:46 PM
I assume every time an item is looted, whether it has or has not been looted before, it gets a brand new item_id?
That is correct.
kurby
04-08-2008, 02:53 PM
Try the small changes I offered, what is the result?
Critical
04-08-2008, 05:31 PM
Alright made the changes to my code.
In my header template on my site, I am using the following code to call the php file:
<script language="JavaScript" type="text/javascript" src="./datacall.php"
<script>
When I put that code in, all it does it break my table structure. No data is showing up.
kurby
04-08-2008, 07:21 PM
You don't have to refer to it like that. PHP is placed directly into your HTML. Just place it in the body of your page, wherever you want the table to appear. Just make sure the file is saved with a .php extension.
Critical
04-09-2008, 05:00 PM
That is the thing though. That file cannot be saved as any extension. It is a template within vBulletin.
Unless, this vBulletin code is already saved as a PHP file and I just do not realize it?
This is what my header template code looks like:
<!-- START HEADER -->
<body onLoad="MM_preloadImages('fp_images/hover_frontpage.gif','fp_images/hover_forums.gif','fp_images/hover_dkp.gif','fp_images/hover_recruitment.gif','fp_images/hover_user.gif','fp_images/hover_register.gif')">
<td height="27" colspan="2" valign="top"><table width="100" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="76" height="27" valign="top"><a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','fp_images/hover_frontpage.gif',1)"><img src="fp_images/nohover_frontpage.gif" name="Image2" width="76" height="27" border="0" /></a></td>
<td width="67" height="27" valign="top"><a href="forumlist.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','fp_images/hover_forums.gif',1)"><img src="fp_images/nohover_forums.gif" name="Image3" width="67" height="27" border="0" /></a></td>
<td width="76" height="27" valign="top"><a href="/eqdkp/listmembers.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image4','','fp_images/hover_dkp.gif',1)"><img src="fp_images/nohover_dkp.gif" name="Image4" width="99" height="27" border="0" /></a></td>
<td width="89" height="27" valign="top"><a href="forumdisplay.php?f=6" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image5','','fp_images/hover_recruitment.gif',1)"><img src="fp_images/nohover_recruitment.gif" name="Image5" width="89" height="27" border="0" /></a></td>
<td width="73" height="27" valign="top"><a href="usercp.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image6','','fp_images/hover_user.gif',1)"><img src="fp_images/nohover_user.gif" name="Image6" width="73" height="27" border="0" /></a></td>
<td width="61" height="27" valign="top"><a href="register.php" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image7','','fp_images/hover_register.gif',1)"><img src="fp_images/nohover_register.gif" name="Image7" width="61" height="27" border="0" /></a></td>
</tr>
</table>
</td>
<td width="465" height="227" valign="top"><table width="100" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="465" height="227" valign="top"><img src="fp_images/guild_name.gif" width="465" height="227" /></td>
</tr>
</table></td>
<br />
<br />
<!-- END HEADER -->
<!-- NAVBAR POPUP MENUS -->
<if condition="$show['popups']">
<if condition="$show['searchbuttons']">
<!-- header quick search form -->
<div class="vbmenu_popup" id="navbar_search_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead">$vbphrase[search_forums]</td>
</tr>
<tr>
<td class="vbmenu_option" title="nohilite">
<form action="search.php" method="post">
<input type="hidden" name="do" value="process" />
<input type="hidden" name="showposts" value="0" />
<input type="hidden" name="quicksearch" value="1" />
<input type="hidden" name="s" value="$session[sessionhash]" />
<input type="text" class="bginput" name="query" size="20" /> $gobutton<br />
</form>
</td>
</tr>
<tr>
<td class="vbmenu_option"><a href="search.php$session[sessionurl_q]" accesskey="4" rel="nofollow">$vbphrase[advanced_search]</a></td>
</tr>
</table>
</div>
<!-- / header quick search form -->
</if>
<if condition="$show['member']">
<!-- user cp tools menu -->
<div class="vbmenu_popup" id="usercptools_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr><td class="thead">$vbphrase[quick_links]</td></tr>
<if condition="$vboptions['enablesearches']"><tr><td class="vbmenu_option"><a href="search.php?$session[sessionurl]do=getdaily">$vbphrase[todays_posts]</a></td></tr></if>
<tr><td class="vbmenu_option"><a href="forumdisplay.php?$session[sessionurl]do=markread">$vbphrase[mark_forums_read]</a></td></tr>
<tr><td class="vbmenu_option"><a href="#" onclick="window.open('misc.php?$session[sessionurl]do=buddylist&focus=1','buddylist','statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,w idth=250,height=300'); return false;">$vbphrase[open_buddy_list]</a></td></tr>
<tr><td class="thead"><a href="usercp.php$session[sessionurl_q]">$vbphrase[user_control_panel]</a></td></tr>
<if condition="$show['siglink']"><tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=editsignature">$vbphrase[edit_signature]</a></td></tr></if>
<!--<if condition="$show['avatarlink']"><tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=editavatar">$vbphrase[edit_avatar]</a></td></tr></if>-->
<tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=editprofile">$vbphrase[edit_profile]</a></td></tr>
<tr><td class="vbmenu_option"><a href="profile.php?$session[sessionurl]do=editoptions">$vbphrase[edit_options]</a></td></tr>
<tr><td class="thead">$vbphrase[miscellaneous]</td></tr>
<if condition="$show['pmstats']"><tr><td class="vbmenu_option"><a href="private.php$session[sessionurl_q]" rel="nofollow">$vbphrase[private_messages]</a></td></tr></if>
<tr><td class="vbmenu_option"><a href="subscription.php$session[sessionurl_q]" rel="nofollow">$vbphrase[subscribed_threads]</a></td></tr>
<tr><td class="vbmenu_option"><a href="member.php?$session[sessionurl]u=$bbuserinfo[userid]">$vbphrase[my_profile]</a></td></tr>
<if condition="$show['wollink']"><tr><td class="vbmenu_option"><a href="online.php$session[sessionurl_q]">$vbphrase[whos_online]</a></td></tr></if>
</table>
</div>
<!-- / user cp tools menu -->
</if>
<!-- / NAVBAR POPUP MENUS -->
<!-- PAGENAV POPUP -->
<div class="vbmenu_popup" id="pagenav_menu" style="display:none">
<table cellpadding="4" cellspacing="1" border="0">
<tr>
<td class="thead" nowrap="nowrap">$vbphrase[go_to_page]</td>
</tr>
<tr>
<td class="vbmenu_option" title="nohilite">
<form action="$vboptions[forumhome].php" method="get" onsubmit="return this.gotopage()" id="pagenav_form">
<input type="text" class="bginput" id="pagenav_itxt" style="font-size:11px" size="4" />
<input type="button" class="button" id="pagenav_ibtn" value="$vbphrase[go]" />
</form>
</td>
</tr>
</table>
</div>
<!-- / PAGENAV POPUP -->
</if>
<!-- content table -->
$spacer_open
$_phpinclude_output
DmitriF
04-09-2008, 06:00 PM
Uhm include the file like you usually would include the external php, then call the function at the needed spot.
The way you are calling it is marginally insane, no offence intended. You are telling the browser its a javascript file, therefore the server when it receives the call may not interpret the php file as php. Basically you are making both sides go haywire.
TheLanyard
04-09-2008, 06:02 PM
You might want to try and iframe the code in or maybe AJAX would be your solution? I don't think you can call a PHP script through a script tag.
<iframe src ="datacall.php" />