| | |
Database - CPanel
Please support our Database Design advertiser: $6.99 Domain Names at 1&1. Includes Free Privacy. Save Now!
Thread Solved |
•
•
Join Date: Jun 2009
Posts: 34
Reputation:
Solved Threads: 0
Actually a more personal example..on my site, I have data show of the name and the description of the achievement. Well each name represents a new achievement. I want to be able to take one specific achievement and show only that just as I show only one table from the database right now. For example, on http://www.wowtah.com/achievements.php?type=general the first achievement is "Level 10". I want the user to be able to click on the achievement and just as the tables do, the info changes to whatever I want it to show then. Does that make sense? So that I could have a section that explains how to gain the achievement, granted, this one in particular doesn't need much explaining.
It would be something like this. I assume you have a column 'id' in your tables that identifies each separate record.
php Syntax (Toggle Plain Text)
<table> <?php $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error()); @mysql_select_db('wowtahc1_achievements') or die(mysql_error()); $id = isset($_GET['id']) ? $_GET['id'] : 0; $type = $_GET['type']; switch ($type) { case 'general': { if ($id < 1) { $query = 'SELECT * FROM general'; $result = @mysql_query($query) or die(mysql_error()); if ($result) { while ($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<th class="title"><a href="achievements.php?type=general&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>'; echo '<td class="description">' . $row['Description'] . '</td>'; echo '</tr>'; } mysql_free_result($result); } } else { $query = "SELECT * FROM general WHERE id=$id"; $result = @mysql_query($query) or die(mysql_error()); if ($result) { if ($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<th class="title">' . $row['Name'] . '</th>'; echo '<td class="description">' . $row['Description'] . '</td>'; echo '</tr>'; } mysql_free_result($result); } } break; } case 'quests': { if ($id < 1) { $query = 'SELECT * FROM quests'; $result = @mysql_query($query) or die(mysql_error()); if ($result) { while ($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<th class="title"><a href="achievements.php?type=quests&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>'; echo '<td class="description">' . $row['Description'] . '</td>'; echo '</tr>'; } mysql_free_result($result); } } else { $query = "SELECT * FROM quests WHERE id=$id"; $result = @mysql_query($query) or die(mysql_error()); if ($result) { if ($row = mysql_fetch_assoc($result)) { echo '<tr>'; echo '<th class="title">' . $row['Name'] . '</th>'; echo '<td class="description">' . $row['Description'] . '</td>'; echo '</tr>'; } mysql_free_result($result); } } break; } } mysql_close($db_link) ?> </table>
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
•
•
Join Date: Jun 2009
Posts: 34
Reputation:
Solved Threads: 0
Thanks again priteas.
I am sure that code will work excellently. I just haven't had a chance to have a go with it. Been so busy with school and work I'm finally now replying to you.
So. I do have another question. I added another field to my database, a blob type like you told me to use for pictures. I attached the picture and then I tried having that also show up on my site and it turned everything into mumbo jumbo. Is there some special way you add a blob field? Do I gotta do something different than I do with these varchar type fields? Here is what the part of my code that I edited looked like:
Whats highlighted in red is what I added. Before that, everything works fine. I even tried replacing 'Name' with 'Picture' just to see if I added the php wrong, but, still same problem. Um, and I guess to make it easier to see what issue is MAYBE the mumbo jumbo that appeared might be useful....
�PNG ��� IHDR���@���@����iq���mIDATx�ݛmp[ՙ�֕4W�m���`�b�<����4i
�����~��t�>v:�~`ٲہ�fg`w��3��NSR�@�`j���1a#GX�*[�Eҽ������x���=���<�9�yιM�,� E�H�ʸ�]�~�)��ݵ�K��^�L�������_}�|� �M(5e��:r����ԧ(���ke�y�Ⱦs@p�x��x�G~�){�C=�@��xפ�@�����8���`�ȭ��xi�%���y�\d�d��x�!�GF��2��q��F�Qa��+��H��eT�>��x�@�Pѹ����5�\u�)� �CЕ��ߧ��g(5���1�x� �+|����:��i��j�:��gP��ޠ�� *�T̼v*��-$:[��
Thats just a small portion of it, but it all looks basically like that, hehe.
I am sure that code will work excellently. I just haven't had a chance to have a go with it. Been so busy with school and work I'm finally now replying to you.So. I do have another question. I added another field to my database, a blob type like you told me to use for pictures. I attached the picture and then I tried having that also show up on my site and it turned everything into mumbo jumbo. Is there some special way you add a blob field? Do I gotta do something different than I do with these varchar type fields? Here is what the part of my code that I edited looked like:
case 'general': {
$query = 'SELECT * FROM general';
$result = @mysql_query($query) or die(mysql_error());
if ($result)
{
while ($row = mysql_fetch_assoc($result))
{
echo '<br/>' . '<br/>';
echo $row['Picture'] . '<span class="title">' . $row['Name'] . '</span>';
echo '<br/>';
echo '<span class="description">' . $row['Description'] . '</span>';
}
mysql_free_result($result);
}
break;
}Whats highlighted in red is what I added. Before that, everything works fine. I even tried replacing 'Name' with 'Picture' just to see if I added the php wrong, but, still same problem. Um, and I guess to make it easier to see what issue is MAYBE the mumbo jumbo that appeared might be useful....
�PNG ��� IHDR���@���@����iq���mIDATx�ݛmp[ՙ�֕4W�m���`�b�<����4i
�����~��t�>v:�~`ٲہ�fg`w��3��NSR�@�`j���1a#GX�*[�Eҽ������x���=���<�9�yιM�,� E�H�ʸ�]�~�)��ݵ�K��^�L�������_}�|� �M(5e��:r����ԧ(���ke�y�Ⱦs@p�x��x�G~�){�C=�@��xפ�@�����8���`�ȭ��xi�%���y�\d�d��x�!�GF��2��q��F�Qa��+��H��eT�>��x�@�Pѹ����5�\u�)� �CЕ��ߧ��g(5���1�x� �+|����:��i��j�:��gP��ޠ�� *�T̼v*��-$:[��Thats just a small portion of it, but it all looks basically like that, hehe.
A blob field is just binary data, which in your code gets displayed as text. The most easy way would be to create a separate php page that retrieves your image and displays it. I have an example of this in my original admin panel. I'll need some time to make an example for you.
This thread has a working example, so hopefully you won't need a demo from me: http://www.phpbuilder.com/board/show...php?t=10252369
This thread has a working example, so hopefully you won't need a demo from me: http://www.phpbuilder.com/board/show...php?t=10252369
"If it is NOT source, it is NOT software."
-- NASA
-- NASA
•
•
Join Date: Jun 2009
Posts: 34
Reputation:
Solved Threads: 0
Ok. Um. Yea, that code is a little more confusing looking. Could you maybe explain it a little better than that guy? Cuz I did what he said...but..nothing happened other than I got this on my page:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/wowtahc1/public_html/achievements.php on line 7
">
Line 7 is:
<img src="showavatar.php?id="<?php echo mysql_result($avatardetail, 0, "ID"); ?>">
now I realize it could be because of $avatardetail cuz that could be something from the guy's database but I dont know the equivilence of it to mine. I did name the .php I put the code in called showavatar.php for the sake of simplicity for now so I know that isn't the issue.
But, I don't think that's the only issue we will run into so, lets also solve some others. Here is the code I put in, (for the sake of showing you my changes trying to get it to function with my database):
I highlighted in red again the changes that I made. I think also I should change "Avatar"? but I dont know to what. Also, I don't see how in this code I can place the image where I want it....
Also, whats tools.php? That code says it requires it and, I can see it on my tabs, it's there, but it's blank.
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/wowtahc1/public_html/achievements.php on line 7
">
Line 7 is:
<img src="showavatar.php?id="<?php echo mysql_result($avatardetail, 0, "ID"); ?>">
now I realize it could be because of $avatardetail cuz that could be something from the guy's database but I dont know the equivilence of it to mine. I did name the .php I put the code in called showavatar.php for the sake of simplicity for now so I know that isn't the issue.
But, I don't think that's the only issue we will run into so, lets also solve some others. Here is the code I put in, (for the sake of showing you my changes trying to get it to function with my database):
<?php
require("tools.php");
if(isset($id))
{
$filedata = mysql_query("SELECT * FROM general WHERE ID = '".$id."' LIMIT 1");
header("Content-type: \"".mysql_result($filedata, 0, "filetype")."\"");
// Work out whether we can show or download the attachment:
$mimetype = explode("/", $row["filetype"]);
if($mimetype[0] != "Picture")
{
header("Content-length: ".mysql_result($filedata, 0, "filesize"));
header("Content-Disposition: attachment; filename=".mysql_result($filedata, 0, "filename"));
header("Content-Description: PHP Generated Data");
}
echo mysql_result($filedata, 0, "Avatar");
}
?>I highlighted in red again the changes that I made. I think also I should change "Avatar"? but I dont know to what. Also, I don't see how in this code I can place the image where I want it....
Also, whats tools.php? That code says it requires it and, I can see it on my tabs, it's there, but it's blank.
![]() |
Similar Threads
- help im getting error with syntax on this registration script (MySQL)
- Free Social Web Hosting - 0bones.com (Web Hosting Deals)
- Need PHP/MYSQL database help (PHP)
- Check and Repair MySQL Database (MySQL)
- Database and web design (MySQL)
- Copying a database to another server (MySQL)
- show content from another sites's database (PHP)
- Automatic email creation in cpanel ----PHP (PHP)
- Remotly Hosted MySQL Database (MySQL)
Other Threads in the Database Design Forum
- Previous Thread: Database Newbie
- Next Thread: ERD for social networking website
Views: 6831 | Replies: 61
| Thread Tools | Search this Thread |
Tag cloud for Database Design






