943,862 Members | Top Members by Rank

Ad:
You are currently viewing page 6 of this multi-page discussion thread; Jump to the first page
Sep 1st, 2009
0

Re: Database - CPanel

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Spunky is offline Offline
34 posts
since Jun 2009
Sep 2nd, 2009
0

Re: Database - CPanel

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)
  1. <table>
  2. <?php
  3. $db_link = @mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
  4. @mysql_select_db('wowtahc1_achievements') or die(mysql_error());
  5.  
  6. $id = isset($_GET['id']) ? $_GET['id'] : 0;
  7.  
  8. $type = $_GET['type'];
  9. switch ($type)
  10. {
  11. case 'general': {
  12. if ($id < 1)
  13. {
  14. $query = 'SELECT * FROM general';
  15. $result = @mysql_query($query) or die(mysql_error());
  16. if ($result)
  17. {
  18. while ($row = mysql_fetch_assoc($result))
  19. {
  20. echo '<tr>';
  21. echo '<th class="title"><a href="achievements.php?type=general&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>';
  22. echo '<td class="description">' . $row['Description'] . '</td>';
  23. echo '</tr>';
  24. }
  25. mysql_free_result($result);
  26. }
  27. }
  28. else
  29. {
  30. $query = "SELECT * FROM general WHERE id=$id";
  31. $result = @mysql_query($query) or die(mysql_error());
  32. if ($result)
  33. {
  34. if ($row = mysql_fetch_assoc($result))
  35. {
  36. echo '<tr>';
  37. echo '<th class="title">' . $row['Name'] . '</th>';
  38. echo '<td class="description">' . $row['Description'] . '</td>';
  39. echo '</tr>';
  40. }
  41. mysql_free_result($result);
  42. }
  43. }
  44. break;
  45. }
  46. case 'quests':
  47. {
  48. if ($id < 1)
  49. {
  50. $query = 'SELECT * FROM quests';
  51. $result = @mysql_query($query) or die(mysql_error());
  52. if ($result)
  53. {
  54. while ($row = mysql_fetch_assoc($result))
  55. {
  56. echo '<tr>';
  57. echo '<th class="title"><a href="achievements.php?type=quests&id=' . $row['Id'] . '">' . $row['Name'] . '</a></th>';
  58. echo '<td class="description">' . $row['Description'] . '</td>';
  59. echo '</tr>';
  60. }
  61. mysql_free_result($result);
  62. }
  63. }
  64. else
  65. {
  66. $query = "SELECT * FROM quests WHERE id=$id";
  67. $result = @mysql_query($query) or die(mysql_error());
  68. if ($result)
  69. {
  70. if ($row = mysql_fetch_assoc($result))
  71. {
  72. echo '<tr>';
  73. echo '<th class="title">' . $row['Name'] . '</th>';
  74. echo '<td class="description">' . $row['Description'] . '</td>';
  75. echo '</tr>';
  76. }
  77. mysql_free_result($result);
  78. }
  79. }
  80. break;
  81. }
  82. }
  83. mysql_close($db_link)
  84. ?>
  85. </table>
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 730
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Sep 7th, 2009
0

Re: Database - CPanel

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:

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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Spunky is offline Offline
34 posts
since Jun 2009
Sep 7th, 2009
0

Re: Database - CPanel

lol dont mind the confused smiley in the middle of the mumbo jumbo, it must have had the correct symbols in the correct spot to make that, hahaha.
Reputation Points: 10
Solved Threads: 0
Light Poster
Spunky is offline Offline
34 posts
since Jun 2009
Sep 7th, 2009
0

Re: Database - CPanel

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
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 730
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Sep 8th, 2009
0

Re: Database - CPanel

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):

<?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.
Reputation Points: 10
Solved Threads: 0
Light Poster
Spunky is offline Offline
34 posts
since Jun 2009
Sep 8th, 2009
0

Re: Database - CPanel

You can remove the require(tools), it's something from the other guys code.

You shouldn't have changed "image" into "Picture".

I have a very busy week this week, so I haven't got around to making you a demo.
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 730
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006
Sep 8th, 2009
0

Re: Database - CPanel

Oh its no problem. You take your time. I'm in no hurry.
Reputation Points: 10
Solved Threads: 0
Light Poster
Spunky is offline Offline
34 posts
since Jun 2009
Sep 8th, 2009
0

Re: Database - CPanel

Ok well it's still having a problem with the same line and I still don't understand how I tell it where to put the image.

So whenever you do get a chance to make that demo that would be superb. But like I said before, no rush.
Reputation Points: 10
Solved Threads: 0
Light Poster
Spunky is offline Offline
34 posts
since Jun 2009
Sep 22nd, 2009
0

Re: Database - CPanel

Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 730
Bite my shiny metal ass!
pritaeas is offline Offline
4,177 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Database Design Forum Timeline: Database Newbie
Next Thread in Database Design Forum Timeline: ERD for social networking website





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC